diff --git a/.env.dist b/.env.dist index 0f4af21..1d0af50 100644 --- a/.env.dist +++ b/.env.dist @@ -30,4 +30,4 @@ SEATS_REQUESTED=1 STRICT_FREQUENCY=false # default timezone -DEFAULT_TIMEZONE=Europe/Paris +TIMEZONE=Europe/Paris diff --git a/package-lock.json b/package-lock.json index 2b05cc8..ad6b874 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mobicoop/ad", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mobicoop/ad", - "version": "2.0.0", + "version": "2.1.0", "license": "AGPL", "dependencies": { "@grpc/grpc-js": "^1.8.14", diff --git a/package.json b/package.json index 0b3800c..7ad24a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mobicoop/ad", - "version": "2.0.0", + "version": "2.1.0", "description": "Mobicoop V3 Ad", "author": "sbriat", "private": true, diff --git a/src/modules/ad/core/application/ports/default-params.type.ts b/src/modules/ad/core/application/ports/default-params.type.ts index dbf0798..58f06fb 100644 --- a/src/modules/ad/core/application/ports/default-params.type.ts +++ b/src/modules/ad/core/application/ports/default-params.type.ts @@ -5,5 +5,5 @@ export type DefaultParams = { SEATS_REQUESTED: number; DEPARTURE_TIME_MARGIN: number; STRICT: boolean; - DEFAULT_TIMEZONE: string; + TIMEZONE: string; }; diff --git a/src/modules/ad/infrastructure/default-params-provider.ts b/src/modules/ad/infrastructure/default-params-provider.ts index 32228dd..4063279 100644 --- a/src/modules/ad/infrastructure/default-params-provider.ts +++ b/src/modules/ad/infrastructure/default-params-provider.ts @@ -15,6 +15,6 @@ export class DefaultParamsProvider implements DefaultParamsProviderPort { this._configService.get('DEPARTURE_TIME_MARGIN'), ), STRICT: this._configService.get('STRICT_FREQUENCY') == 'true', - DEFAULT_TIMEZONE: this._configService.get('DEFAULT_TIMEZONE'), + TIMEZONE: this._configService.get('DEFAULT_TIMEZONE'), }); } diff --git a/src/modules/ad/infrastructure/input-datetime-transformer.ts b/src/modules/ad/infrastructure/input-datetime-transformer.ts index faa4025..5181a0a 100644 --- a/src/modules/ad/infrastructure/input-datetime-transformer.ts +++ b/src/modules/ad/infrastructure/input-datetime-transformer.ts @@ -23,7 +23,7 @@ export class InputDateTimeTransformer implements DateTimeTransformerPort { private readonly timezoneFinder: TimezoneFinderPort, @Inject(TIME_CONVERTER) private readonly timeConverter: TimeConverterPort, ) { - this._defaultTimezone = defaultParamsProvider.getParams().DEFAULT_TIMEZONE; + this._defaultTimezone = defaultParamsProvider.getParams().TIMEZONE; } /** @@ -79,7 +79,7 @@ export class InputDateTimeTransformer implements DateTimeTransformerPort { this._defaultTimezone, )[0], ); - return new Date(this.fromDate(geoFromDate, frequency)).getDay(); + return new Date(this.fromDate(geoFromDate, frequency)).getUTCDay(); }; /** diff --git a/src/modules/ad/infrastructure/output-datetime-transformer.ts b/src/modules/ad/infrastructure/output-datetime-transformer.ts index d2d44be..50cef44 100644 --- a/src/modules/ad/infrastructure/output-datetime-transformer.ts +++ b/src/modules/ad/infrastructure/output-datetime-transformer.ts @@ -66,7 +66,7 @@ export class OutputDateTimeTransformer implements DateTimeTransformerPort { geoFromDate.coordinates.lat, )[0], ); - return new Date(this.fromDate(geoFromDate, frequency)).getDay(); + return new Date(this.fromDate(geoFromDate, frequency)).getUTCDay(); }; /** diff --git a/src/modules/ad/infrastructure/time-converter.ts b/src/modules/ad/infrastructure/time-converter.ts index a08ac63..462473c 100644 --- a/src/modules/ad/infrastructure/time-converter.ts +++ b/src/modules/ad/infrastructure/time-converter.ts @@ -6,91 +6,52 @@ import { TimeConverterPort } from '../core/application/ports/time-converter.port export class TimeConverter implements TimeConverterPort { private readonly UNIX_EPOCH = '1970-01-01'; - localStringTimeToUtcStringTime = (time: string, timezone: string): string => { - try { - if (!time || !timezone) throw new Error(); - return new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone(timezone)) - .convert(TimeZone.zone('UTC')) - .format('HH:mm'); - } catch (e) { - return undefined; - } - }; + localStringTimeToUtcStringTime = (time: string, timezone: string): string => + new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone(timezone)) + .convert(TimeZone.zone('UTC')) + .format('HH:mm'); - utcStringTimeToLocalStringTime = (time: string, timezone: string): string => { - try { - if (!time || !timezone) throw new Error(); - return new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC')) - .convert(TimeZone.zone(timezone)) - .format('HH:mm'); - } catch (e) { - return undefined; - } - }; + utcStringTimeToLocalStringTime = (time: string, timezone: string): string => + new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC')) + .convert(TimeZone.zone(timezone)) + .format('HH:mm'); localStringDateTimeToUtcDate = ( date: string, time: string, timezone: string, - dst = true, - ): Date => { - try { - if (!date || !time || !timezone) throw new Error(); - return new Date( - new DateTime( - `${date}T${time}`, - TimeZone.zone(timezone, dst), - ).toIsoString(), - ); - } catch (e) { - return undefined; - } - }; + dst = false, + ): Date => + new Date( + new DateTime( + `${date}T${time}`, + TimeZone.zone(timezone, dst), + ).toIsoString(), + ); utcStringDateTimeToLocalIsoString = ( date: string, time: string, timezone: string, - dst?: boolean, - ): string => { - try { - if (!date || !time || !timezone) throw new Error(); - return new DateTime(`${date}T${time}`, TimeZone.zone('UTC')) - .convert(TimeZone.zone(timezone, dst)) - .toIsoString(); - } catch (e) { - return undefined; - } - }; + dst = false, + ): string => + new DateTime(`${date}T${time}`, TimeZone.zone('UTC')) + .convert(TimeZone.zone(timezone, dst)) + .toIsoString(); - utcUnixEpochDayFromTime = (time: string, timezone: string): number => { - try { - if (!time || !timezone) throw new Error(); - return new Date( - new DateTime( - `${this.UNIX_EPOCH}T${time}`, - TimeZone.zone(timezone, false), - ) - .convert(TimeZone.zone('UTC')) - .toIsoString() - .split('T')[0], - ).getDay(); - } catch (e) { - return undefined; - } - }; + utcUnixEpochDayFromTime = (time: string, timezone: string): number => + new Date( + new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone(timezone, false)) + .convert(TimeZone.zone('UTC')) + .toIsoString() + .split('T')[0], + ).getUTCDay(); - localUnixEpochDayFromTime = (time: string, timezone: string): number => { - try { - if (!time || !timezone) throw new Error(); - return new Date( - new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC')) - .convert(TimeZone.zone(timezone)) - .toIsoString() - .split('T')[0], - ).getDay(); - } catch (e) { - return undefined; - } - }; + localUnixEpochDayFromTime = (time: string, timezone: string): number => + new Date( + new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC')) + .convert(TimeZone.zone(timezone)) + .toIsoString() + .split('T')[0], + ).getUTCDay(); } diff --git a/src/modules/ad/tests/unit/core/create-ad.service.spec.ts b/src/modules/ad/tests/unit/core/create-ad.service.spec.ts index 6413c43..8527d4d 100644 --- a/src/modules/ad/tests/unit/core/create-ad.service.spec.ts +++ b/src/modules/ad/tests/unit/core/create-ad.service.spec.ts @@ -71,7 +71,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = { PASSENGER: true, SEATS_REQUESTED: 1, STRICT: false, - DEFAULT_TIMEZONE: 'Europe/Paris', + TIMEZONE: 'Europe/Paris', }; }, }; diff --git a/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts b/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts index 5d017e5..3de2b92 100644 --- a/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts @@ -53,6 +53,6 @@ describe('DefaultParamsProvider', () => { expect(params.DEPARTURE_TIME_MARGIN).toBe(900); expect(params.PASSENGER).toBeTruthy(); expect(params.DRIVER).toBeFalsy(); - expect(params.DEFAULT_TIMEZONE).toBe('Europe/Paris'); + expect(params.TIMEZONE).toBe('Europe/Paris'); }); }); diff --git a/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts b/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts index 11733a0..3046013 100644 --- a/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts @@ -19,7 +19,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = { PASSENGER: true, SEATS_REQUESTED: 1, STRICT: false, - DEFAULT_TIMEZONE: 'Europe/Paris', + TIMEZONE: 'Europe/Paris', }; }, }; diff --git a/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts b/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts index 4c3dcf8..62fe6ed 100644 --- a/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts @@ -19,7 +19,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = { PASSENGER: true, SEATS_REQUESTED: 1, STRICT: false, - DEFAULT_TIMEZONE: 'Europe/Paris', + TIMEZONE: 'Europe/Paris', }; }, }; diff --git a/src/modules/ad/tests/unit/infrastructure/time-converter.spec.ts b/src/modules/ad/tests/unit/infrastructure/time-converter.spec.ts index bdfee03..45941f1 100644 --- a/src/modules/ad/tests/unit/infrastructure/time-converter.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/time-converter.spec.ts @@ -16,41 +16,12 @@ describe('Time Converter', () => { ); expect(utcDatetime).toBe('07:00'); }); - it('should return undefined if time is invalid', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const parisTime = '28:00'; - const utcDatetime = timeConverter.localStringTimeToUtcStringTime( - parisTime, - 'Europe/Paris', - ); - expect(utcDatetime).toBeUndefined(); - }); - it('should return undefined if time is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const parisTime = undefined; - const utcDatetime = timeConverter.localStringTimeToUtcStringTime( - parisTime, - 'Europe/Paris', - ); - expect(utcDatetime).toBeUndefined(); - }); - it('should return undefined if timezone is invalid', () => { + it('should throw an error if timezone is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const fooBarTime = '08:00'; - const utcDatetime = timeConverter.localStringTimeToUtcStringTime( - fooBarTime, - 'Foo/Bar', - ); - expect(utcDatetime).toBeUndefined(); - }); - it('should return undefined if timezone is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const fooBarTime = '08:00'; - const utcDatetime = timeConverter.localStringTimeToUtcStringTime( - fooBarTime, - undefined, - ); - expect(utcDatetime).toBeUndefined(); + expect(() => { + timeConverter.localStringTimeToUtcStringTime(fooBarTime, 'Foo/Bar'); + }).toThrow(); }); }); @@ -64,46 +35,24 @@ describe('Time Converter', () => { ); expect(parisTime).toBe('08:00'); }); - it('should return undefined if time is invalid', () => { + it('should throw an error if time is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const utcTime = '27:00'; - const parisTime = timeConverter.utcStringTimeToLocalStringTime( - utcTime, - 'Europe/Paris', - ); - expect(parisTime).toBeUndefined(); + expect(() => { + timeConverter.utcStringTimeToLocalStringTime(utcTime, 'Europe/Paris'); + }).toThrow(); }); - it('should return undefined if time is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const utcTime = undefined; - const parisTime = timeConverter.utcStringTimeToLocalStringTime( - utcTime, - 'Europe/Paris', - ); - expect(parisTime).toBeUndefined(); - }); - it('should return undefined if timezone is invalid', () => { + it('should throw an error if timezone is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const utcTime = '07:00'; - const parisTime = timeConverter.utcStringTimeToLocalStringTime( - utcTime, - 'Foo/Bar', - ); - expect(parisTime).toBeUndefined(); - }); - it('should return undefined if timezone is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const utcTime = '07:00'; - const parisTime = timeConverter.utcStringTimeToLocalStringTime( - utcTime, - undefined, - ); - expect(parisTime).toBeUndefined(); + expect(() => { + timeConverter.utcStringTimeToLocalStringTime(utcTime, 'Foo/Bar'); + }).toThrow(); }); }); describe('localStringDateTimeToUtcDate', () => { - it('should convert a summer paris date and time to a utc date', () => { + it('should convert a summer paris date and time to a utc date with dst', () => { const timeConverter: TimeConverter = new TimeConverter(); const parisDate = '2023-06-22'; const parisTime = '12:00'; @@ -111,10 +60,11 @@ describe('Time Converter', () => { parisDate, parisTime, 'Europe/Paris', + true, ); expect(utcDate.toISOString()).toBe('2023-06-22T10:00:00.000Z'); }); - it('should convert a winter paris date and time to a utc date', () => { + it('should convert a winter paris date and time to a utc date with dst', () => { const timeConverter: TimeConverter = new TimeConverter(); const parisDate = '2023-02-02'; const parisTime = '12:00'; @@ -122,6 +72,7 @@ describe('Time Converter', () => { parisDate, parisTime, 'Europe/Paris', + true, ); expect(utcDate.toISOString()).toBe('2023-02-02T11:00:00.000Z'); }); @@ -133,7 +84,6 @@ describe('Time Converter', () => { parisDate, parisTime, 'Europe/Paris', - false, ); expect(utcDate.toISOString()).toBe('2023-06-22T11:00:00.000Z'); }); @@ -159,75 +109,69 @@ describe('Time Converter', () => { ); expect(utcDate.toISOString()).toBe('2023-02-03T01:00:00.000Z'); }); - it('should return undefined if date is invalid', () => { + it('should throw an error if date is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const parisDate = '2023-06-32'; const parisTime = '08:00'; - const utcDate = timeConverter.localStringDateTimeToUtcDate( - parisDate, - parisTime, - 'Europe/Paris', - ); - expect(utcDate).toBeUndefined(); + expect(() => { + timeConverter.localStringDateTimeToUtcDate( + parisDate, + parisTime, + 'Europe/Paris', + ); + }).toThrow(); }); - it('should return undefined if date is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const parisDate = undefined; - const parisTime = '08:00'; - const utcDate = timeConverter.localStringDateTimeToUtcDate( - parisDate, - parisTime, - 'Europe/Paris', - ); - expect(utcDate).toBeUndefined(); - }); - it('should return undefined if time is invalid', () => { + it('should throw an error if time is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const parisDate = '2023-06-22'; const parisTime = '28:00'; - const utcDate = timeConverter.localStringDateTimeToUtcDate( - parisDate, - parisTime, - 'Europe/Paris', - ); - expect(utcDate).toBeUndefined(); + expect(() => { + timeConverter.localStringDateTimeToUtcDate( + parisDate, + parisTime, + 'Europe/Paris', + ); + }).toThrow(); }); - it('should return undefined if time is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const parisDate = '2023-06-22'; - const parisTime = undefined; - const utcDate = timeConverter.localStringDateTimeToUtcDate( - parisDate, - parisTime, - 'Europe/Paris', - ); - expect(utcDate).toBeUndefined(); - }); - it('should return undefined if timezone is invalid', () => { + it('should throw an error if timezone is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const parisDate = '2023-06-22'; const parisTime = '12:00'; - const utcDate = timeConverter.localStringDateTimeToUtcDate( - parisDate, - parisTime, - 'Foo/Bar', - ); - expect(utcDate).toBeUndefined(); - }); - it('should return undefined if timezone is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const parisDate = '2023-06-22'; - const parisTime = '12:00'; - const utcDate = timeConverter.localStringDateTimeToUtcDate( - parisDate, - parisTime, - undefined, - ); - expect(utcDate).toBeUndefined(); + expect(() => { + timeConverter.localStringDateTimeToUtcDate( + parisDate, + parisTime, + 'Foo/Bar', + ); + }).toThrow(); }); }); describe('utcStringDateTimeToLocalIsoString', () => { + it('should convert a utc string date and time to a summer paris date isostring with dst', () => { + const timeConverter: TimeConverter = new TimeConverter(); + const utcDate = '2023-06-22'; + const utcTime = '10:00'; + const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString( + utcDate, + utcTime, + 'Europe/Paris', + true, + ); + expect(localIsoString).toBe('2023-06-22T12:00:00.000+02:00'); + }); + it('should convert a utc string date and time to a winter paris date isostring with dst', () => { + const timeConverter: TimeConverter = new TimeConverter(); + const utcDate = '2023-02-02'; + const utcTime = '10:00'; + const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString( + utcDate, + utcTime, + 'Europe/Paris', + true, + ); + expect(localIsoString).toBe('2023-02-02T11:00:00.000+01:00'); + }); it('should convert a utc string date and time to a summer paris date isostring', () => { const timeConverter: TimeConverter = new TimeConverter(); const utcDate = '2023-06-22'; @@ -237,29 +181,6 @@ describe('Time Converter', () => { utcTime, 'Europe/Paris', ); - expect(localIsoString).toBe('2023-06-22T12:00:00.000+02:00'); - }); - it('should convert a utc string date and time to a winter paris date isostring', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const utcDate = '2023-02-02'; - const utcTime = '10:00'; - const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - 'Europe/Paris', - ); - expect(localIsoString).toBe('2023-02-02T11:00:00.000+01:00'); - }); - it('should convert a utc string date and time to a summer paris date isostring without dst', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const utcDate = '2023-06-22'; - const utcTime = '10:00'; - const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - 'Europe/Paris', - false, - ); expect(localIsoString).toBe('2023-06-22T11:00:00.000+01:00'); }); it('should convert a utc date to a tonga date isostring', () => { @@ -284,71 +205,41 @@ describe('Time Converter', () => { ); expect(localIsoString).toBe('2023-02-02T15:00:00.000-10:00'); }); - it('should return undefined if date is invalid', () => { + it('should throw an error if date is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const utcDate = '2023-06-32'; const utcTime = '07:00'; - const parisTime = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - 'Europe/Paris', - ); - expect(parisTime).toBeUndefined(); + expect(() => { + timeConverter.utcStringDateTimeToLocalIsoString( + utcDate, + utcTime, + 'Europe/Paris', + ); + }).toThrow(); }); - it('should return undefined if date is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const utcDate = undefined; - const utcTime = '07:00'; - const parisTime = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - 'Europe/Paris', - ); - expect(parisTime).toBeUndefined(); - }); - it('should return undefined if time is invalid', () => { + it('should throw an error if time is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const utcDate = '2023-06-22'; const utcTime = '27:00'; - const parisTime = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - 'Europe/Paris', - ); - expect(parisTime).toBeUndefined(); + expect(() => { + timeConverter.utcStringDateTimeToLocalIsoString( + utcDate, + utcTime, + 'Europe/Paris', + ); + }).toThrow(); }); - it('should return undefined if time is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const utcDate = '2023-06-22'; - const utcTime = undefined; - const parisTime = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - 'Europe/Paris', - ); - expect(parisTime).toBeUndefined(); - }); - it('should return undefined if timezone is invalid', () => { + it('should throw an error if timezone is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); const utcDate = '2023-06-22'; const utcTime = '07:00'; - const parisTime = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - 'Foo/Bar', - ); - expect(parisTime).toBeUndefined(); - }); - it('should return undefined if timezone is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - const utcDate = '2023-06-22'; - const utcTime = '07:00'; - const parisTime = timeConverter.utcStringDateTimeToLocalIsoString( - utcDate, - utcTime, - undefined, - ); - expect(parisTime).toBeUndefined(); + expect(() => { + timeConverter.utcStringDateTimeToLocalIsoString( + utcDate, + utcTime, + 'Foo/Bar', + ); + }).toThrow(); }); }); @@ -371,29 +262,17 @@ describe('Time Converter', () => { timeConverter.utcUnixEpochDayFromTime('16:00', 'Pacific/Tahiti'), ).toBe(5); }); - it('should return undefined if time is invalid', () => { + it('should throw an error if time is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.utcUnixEpochDayFromTime('28:00', 'Europe/Paris'), - ).toBeUndefined(); + expect(() => { + timeConverter.utcUnixEpochDayFromTime('28:00', 'Europe/Paris'); + }).toThrow(); }); - it('should return undefined if time is undefined', () => { + it('should throw an error if timezone is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.utcUnixEpochDayFromTime(undefined, 'Europe/Paris'), - ).toBeUndefined(); - }); - it('should return undefined if timezone is invalid', () => { - const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.utcUnixEpochDayFromTime('12:00', 'Foo/Bar'), - ).toBeUndefined(); - }); - it('should return undefined if timezone is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.utcUnixEpochDayFromTime('12:00', undefined), - ).toBeUndefined(); + expect(() => { + timeConverter.utcUnixEpochDayFromTime('12:00', 'Foo/Bar'); + }).toThrow(); }); }); @@ -416,29 +295,17 @@ describe('Time Converter', () => { timeConverter.localUnixEpochDayFromTime('05:00', 'Pacific/Tahiti'), ).toBe(3); }); - it('should return undefined if time is invalid', () => { + it('should throw an error if time is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.localUnixEpochDayFromTime('28:00', 'Europe/Paris'), - ).toBeUndefined(); + expect(() => { + timeConverter.localUnixEpochDayFromTime('28:00', 'Europe/Paris'); + }).toThrow(); }); - it('should return undefined if time is undefined', () => { + it('should throw an error if timezone is invalid', () => { const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.localUnixEpochDayFromTime(undefined, 'Europe/Paris'), - ).toBeUndefined(); - }); - it('should return undefined if timezone is invalid', () => { - const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.localUnixEpochDayFromTime('12:00', 'Foo/Bar'), - ).toBeUndefined(); - }); - it('should return undefined if timezone is undefined', () => { - const timeConverter: TimeConverter = new TimeConverter(); - expect( - timeConverter.localUnixEpochDayFromTime('12:00', undefined), - ).toBeUndefined(); + expect(() => { + timeConverter.localUnixEpochDayFromTime('12:00', 'Foo/Bar'); + }).toThrow(); }); }); });