Merge branch 'fixDst' into 'main'
Fix dst See merge request v3/service/ad!21
This commit is contained in:
commit
749c542bca
|
@ -30,4 +30,4 @@ SEATS_REQUESTED=1
|
||||||
STRICT_FREQUENCY=false
|
STRICT_FREQUENCY=false
|
||||||
|
|
||||||
# default timezone
|
# default timezone
|
||||||
DEFAULT_TIMEZONE=Europe/Paris
|
TIMEZONE=Europe/Paris
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@mobicoop/ad",
|
"name": "@mobicoop/ad",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@mobicoop/ad",
|
"name": "@mobicoop/ad",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"license": "AGPL",
|
"license": "AGPL",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.8.14",
|
"@grpc/grpc-js": "^1.8.14",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@mobicoop/ad",
|
"name": "@mobicoop/ad",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"description": "Mobicoop V3 Ad",
|
"description": "Mobicoop V3 Ad",
|
||||||
"author": "sbriat",
|
"author": "sbriat",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|
|
@ -5,5 +5,5 @@ export type DefaultParams = {
|
||||||
SEATS_REQUESTED: number;
|
SEATS_REQUESTED: number;
|
||||||
DEPARTURE_TIME_MARGIN: number;
|
DEPARTURE_TIME_MARGIN: number;
|
||||||
STRICT: boolean;
|
STRICT: boolean;
|
||||||
DEFAULT_TIMEZONE: string;
|
TIMEZONE: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,6 @@ export class DefaultParamsProvider implements DefaultParamsProviderPort {
|
||||||
this._configService.get('DEPARTURE_TIME_MARGIN'),
|
this._configService.get('DEPARTURE_TIME_MARGIN'),
|
||||||
),
|
),
|
||||||
STRICT: this._configService.get('STRICT_FREQUENCY') == 'true',
|
STRICT: this._configService.get('STRICT_FREQUENCY') == 'true',
|
||||||
DEFAULT_TIMEZONE: this._configService.get('DEFAULT_TIMEZONE'),
|
TIMEZONE: this._configService.get('DEFAULT_TIMEZONE'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class InputDateTimeTransformer implements DateTimeTransformerPort {
|
||||||
private readonly timezoneFinder: TimezoneFinderPort,
|
private readonly timezoneFinder: TimezoneFinderPort,
|
||||||
@Inject(TIME_CONVERTER) private readonly timeConverter: TimeConverterPort,
|
@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,
|
this._defaultTimezone,
|
||||||
)[0],
|
)[0],
|
||||||
);
|
);
|
||||||
return new Date(this.fromDate(geoFromDate, frequency)).getDay();
|
return new Date(this.fromDate(geoFromDate, frequency)).getUTCDay();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -66,7 +66,7 @@ export class OutputDateTimeTransformer implements DateTimeTransformerPort {
|
||||||
geoFromDate.coordinates.lat,
|
geoFromDate.coordinates.lat,
|
||||||
)[0],
|
)[0],
|
||||||
);
|
);
|
||||||
return new Date(this.fromDate(geoFromDate, frequency)).getDay();
|
return new Date(this.fromDate(geoFromDate, frequency)).getUTCDay();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,91 +6,52 @@ import { TimeConverterPort } from '../core/application/ports/time-converter.port
|
||||||
export class TimeConverter implements TimeConverterPort {
|
export class TimeConverter implements TimeConverterPort {
|
||||||
private readonly UNIX_EPOCH = '1970-01-01';
|
private readonly UNIX_EPOCH = '1970-01-01';
|
||||||
|
|
||||||
localStringTimeToUtcStringTime = (time: string, timezone: string): string => {
|
localStringTimeToUtcStringTime = (time: string, timezone: string): string =>
|
||||||
try {
|
new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone(timezone))
|
||||||
if (!time || !timezone) throw new Error();
|
|
||||||
return new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone(timezone))
|
|
||||||
.convert(TimeZone.zone('UTC'))
|
.convert(TimeZone.zone('UTC'))
|
||||||
.format('HH:mm');
|
.format('HH:mm');
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
utcStringTimeToLocalStringTime = (time: string, timezone: string): string => {
|
utcStringTimeToLocalStringTime = (time: string, timezone: string): string =>
|
||||||
try {
|
new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC'))
|
||||||
if (!time || !timezone) throw new Error();
|
|
||||||
return new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC'))
|
|
||||||
.convert(TimeZone.zone(timezone))
|
.convert(TimeZone.zone(timezone))
|
||||||
.format('HH:mm');
|
.format('HH:mm');
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
localStringDateTimeToUtcDate = (
|
localStringDateTimeToUtcDate = (
|
||||||
date: string,
|
date: string,
|
||||||
time: string,
|
time: string,
|
||||||
timezone: string,
|
timezone: string,
|
||||||
dst = true,
|
dst = false,
|
||||||
): Date => {
|
): Date =>
|
||||||
try {
|
new Date(
|
||||||
if (!date || !time || !timezone) throw new Error();
|
|
||||||
return new Date(
|
|
||||||
new DateTime(
|
new DateTime(
|
||||||
`${date}T${time}`,
|
`${date}T${time}`,
|
||||||
TimeZone.zone(timezone, dst),
|
TimeZone.zone(timezone, dst),
|
||||||
).toIsoString(),
|
).toIsoString(),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
utcStringDateTimeToLocalIsoString = (
|
utcStringDateTimeToLocalIsoString = (
|
||||||
date: string,
|
date: string,
|
||||||
time: string,
|
time: string,
|
||||||
timezone: string,
|
timezone: string,
|
||||||
dst?: boolean,
|
dst = false,
|
||||||
): string => {
|
): string =>
|
||||||
try {
|
new DateTime(`${date}T${time}`, TimeZone.zone('UTC'))
|
||||||
if (!date || !time || !timezone) throw new Error();
|
|
||||||
return new DateTime(`${date}T${time}`, TimeZone.zone('UTC'))
|
|
||||||
.convert(TimeZone.zone(timezone, dst))
|
.convert(TimeZone.zone(timezone, dst))
|
||||||
.toIsoString();
|
.toIsoString();
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
utcUnixEpochDayFromTime = (time: string, timezone: string): number => {
|
utcUnixEpochDayFromTime = (time: string, timezone: string): number =>
|
||||||
try {
|
new Date(
|
||||||
if (!time || !timezone) throw new Error();
|
new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone(timezone, false))
|
||||||
return new Date(
|
|
||||||
new DateTime(
|
|
||||||
`${this.UNIX_EPOCH}T${time}`,
|
|
||||||
TimeZone.zone(timezone, false),
|
|
||||||
)
|
|
||||||
.convert(TimeZone.zone('UTC'))
|
.convert(TimeZone.zone('UTC'))
|
||||||
.toIsoString()
|
.toIsoString()
|
||||||
.split('T')[0],
|
.split('T')[0],
|
||||||
).getDay();
|
).getUTCDay();
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
localUnixEpochDayFromTime = (time: string, timezone: string): number => {
|
localUnixEpochDayFromTime = (time: string, timezone: string): number =>
|
||||||
try {
|
new Date(
|
||||||
if (!time || !timezone) throw new Error();
|
|
||||||
return new Date(
|
|
||||||
new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC'))
|
new DateTime(`${this.UNIX_EPOCH}T${time}`, TimeZone.zone('UTC'))
|
||||||
.convert(TimeZone.zone(timezone))
|
.convert(TimeZone.zone(timezone))
|
||||||
.toIsoString()
|
.toIsoString()
|
||||||
.split('T')[0],
|
.split('T')[0],
|
||||||
).getDay();
|
).getUTCDay();
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||||
PASSENGER: true,
|
PASSENGER: true,
|
||||||
SEATS_REQUESTED: 1,
|
SEATS_REQUESTED: 1,
|
||||||
STRICT: false,
|
STRICT: false,
|
||||||
DEFAULT_TIMEZONE: 'Europe/Paris',
|
TIMEZONE: 'Europe/Paris',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,6 +53,6 @@ describe('DefaultParamsProvider', () => {
|
||||||
expect(params.DEPARTURE_TIME_MARGIN).toBe(900);
|
expect(params.DEPARTURE_TIME_MARGIN).toBe(900);
|
||||||
expect(params.PASSENGER).toBeTruthy();
|
expect(params.PASSENGER).toBeTruthy();
|
||||||
expect(params.DRIVER).toBeFalsy();
|
expect(params.DRIVER).toBeFalsy();
|
||||||
expect(params.DEFAULT_TIMEZONE).toBe('Europe/Paris');
|
expect(params.TIMEZONE).toBe('Europe/Paris');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||||
PASSENGER: true,
|
PASSENGER: true,
|
||||||
SEATS_REQUESTED: 1,
|
SEATS_REQUESTED: 1,
|
||||||
STRICT: false,
|
STRICT: false,
|
||||||
DEFAULT_TIMEZONE: 'Europe/Paris',
|
TIMEZONE: 'Europe/Paris',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||||
PASSENGER: true,
|
PASSENGER: true,
|
||||||
SEATS_REQUESTED: 1,
|
SEATS_REQUESTED: 1,
|
||||||
STRICT: false,
|
STRICT: false,
|
||||||
DEFAULT_TIMEZONE: 'Europe/Paris',
|
TIMEZONE: 'Europe/Paris',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,41 +16,12 @@ describe('Time Converter', () => {
|
||||||
);
|
);
|
||||||
expect(utcDatetime).toBe('07:00');
|
expect(utcDatetime).toBe('07:00');
|
||||||
});
|
});
|
||||||
it('should return undefined if time is invalid', () => {
|
it('should throw an error if timezone 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', () => {
|
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
const fooBarTime = '08:00';
|
const fooBarTime = '08:00';
|
||||||
const utcDatetime = timeConverter.localStringTimeToUtcStringTime(
|
expect(() => {
|
||||||
fooBarTime,
|
timeConverter.localStringTimeToUtcStringTime(fooBarTime, 'Foo/Bar');
|
||||||
'Foo/Bar',
|
}).toThrow();
|
||||||
);
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,46 +35,24 @@ describe('Time Converter', () => {
|
||||||
);
|
);
|
||||||
expect(parisTime).toBe('08:00');
|
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 timeConverter: TimeConverter = new TimeConverter();
|
||||||
const utcTime = '27:00';
|
const utcTime = '27:00';
|
||||||
const parisTime = timeConverter.utcStringTimeToLocalStringTime(
|
expect(() => {
|
||||||
utcTime,
|
timeConverter.utcStringTimeToLocalStringTime(utcTime, 'Europe/Paris');
|
||||||
'Europe/Paris',
|
}).toThrow();
|
||||||
);
|
|
||||||
expect(parisTime).toBeUndefined();
|
|
||||||
});
|
});
|
||||||
it('should return undefined if time is undefined', () => {
|
it('should throw an error if timezone is invalid', () => {
|
||||||
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', () => {
|
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
const utcTime = '07:00';
|
const utcTime = '07:00';
|
||||||
const parisTime = timeConverter.utcStringTimeToLocalStringTime(
|
expect(() => {
|
||||||
utcTime,
|
timeConverter.utcStringTimeToLocalStringTime(utcTime, 'Foo/Bar');
|
||||||
'Foo/Bar',
|
}).toThrow();
|
||||||
);
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('localStringDateTimeToUtcDate', () => {
|
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 timeConverter: TimeConverter = new TimeConverter();
|
||||||
const parisDate = '2023-06-22';
|
const parisDate = '2023-06-22';
|
||||||
const parisTime = '12:00';
|
const parisTime = '12:00';
|
||||||
|
@ -111,10 +60,11 @@ describe('Time Converter', () => {
|
||||||
parisDate,
|
parisDate,
|
||||||
parisTime,
|
parisTime,
|
||||||
'Europe/Paris',
|
'Europe/Paris',
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
expect(utcDate.toISOString()).toBe('2023-06-22T10:00:00.000Z');
|
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 timeConverter: TimeConverter = new TimeConverter();
|
||||||
const parisDate = '2023-02-02';
|
const parisDate = '2023-02-02';
|
||||||
const parisTime = '12:00';
|
const parisTime = '12:00';
|
||||||
|
@ -122,6 +72,7 @@ describe('Time Converter', () => {
|
||||||
parisDate,
|
parisDate,
|
||||||
parisTime,
|
parisTime,
|
||||||
'Europe/Paris',
|
'Europe/Paris',
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
expect(utcDate.toISOString()).toBe('2023-02-02T11:00:00.000Z');
|
expect(utcDate.toISOString()).toBe('2023-02-02T11:00:00.000Z');
|
||||||
});
|
});
|
||||||
|
@ -133,7 +84,6 @@ describe('Time Converter', () => {
|
||||||
parisDate,
|
parisDate,
|
||||||
parisTime,
|
parisTime,
|
||||||
'Europe/Paris',
|
'Europe/Paris',
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
expect(utcDate.toISOString()).toBe('2023-06-22T11:00:00.000Z');
|
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');
|
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 timeConverter: TimeConverter = new TimeConverter();
|
||||||
const parisDate = '2023-06-32';
|
const parisDate = '2023-06-32';
|
||||||
const parisTime = '08:00';
|
const parisTime = '08:00';
|
||||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
expect(() => {
|
||||||
|
timeConverter.localStringDateTimeToUtcDate(
|
||||||
parisDate,
|
parisDate,
|
||||||
parisTime,
|
parisTime,
|
||||||
'Europe/Paris',
|
'Europe/Paris',
|
||||||
);
|
);
|
||||||
expect(utcDate).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it('should return undefined if date is undefined', () => {
|
it('should throw an error if time is invalid', () => {
|
||||||
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', () => {
|
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
const parisDate = '2023-06-22';
|
const parisDate = '2023-06-22';
|
||||||
const parisTime = '28:00';
|
const parisTime = '28:00';
|
||||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
expect(() => {
|
||||||
|
timeConverter.localStringDateTimeToUtcDate(
|
||||||
parisDate,
|
parisDate,
|
||||||
parisTime,
|
parisTime,
|
||||||
'Europe/Paris',
|
'Europe/Paris',
|
||||||
);
|
);
|
||||||
expect(utcDate).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it('should return undefined if time is undefined', () => {
|
it('should throw an error if timezone is invalid', () => {
|
||||||
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', () => {
|
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
const parisDate = '2023-06-22';
|
const parisDate = '2023-06-22';
|
||||||
const parisTime = '12:00';
|
const parisTime = '12:00';
|
||||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
expect(() => {
|
||||||
|
timeConverter.localStringDateTimeToUtcDate(
|
||||||
parisDate,
|
parisDate,
|
||||||
parisTime,
|
parisTime,
|
||||||
'Foo/Bar',
|
'Foo/Bar',
|
||||||
);
|
);
|
||||||
expect(utcDate).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('utcStringDateTimeToLocalIsoString', () => {
|
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', () => {
|
it('should convert a utc string date and time to a summer paris date isostring', () => {
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
const utcDate = '2023-06-22';
|
const utcDate = '2023-06-22';
|
||||||
|
@ -237,29 +181,6 @@ describe('Time Converter', () => {
|
||||||
utcTime,
|
utcTime,
|
||||||
'Europe/Paris',
|
'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');
|
expect(localIsoString).toBe('2023-06-22T11:00:00.000+01:00');
|
||||||
});
|
});
|
||||||
it('should convert a utc date to a tonga date isostring', () => {
|
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');
|
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 timeConverter: TimeConverter = new TimeConverter();
|
||||||
const utcDate = '2023-06-32';
|
const utcDate = '2023-06-32';
|
||||||
const utcTime = '07:00';
|
const utcTime = '07:00';
|
||||||
const parisTime = timeConverter.utcStringDateTimeToLocalIsoString(
|
expect(() => {
|
||||||
|
timeConverter.utcStringDateTimeToLocalIsoString(
|
||||||
utcDate,
|
utcDate,
|
||||||
utcTime,
|
utcTime,
|
||||||
'Europe/Paris',
|
'Europe/Paris',
|
||||||
);
|
);
|
||||||
expect(parisTime).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it('should return undefined if date is undefined', () => {
|
it('should throw an error if time is invalid', () => {
|
||||||
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', () => {
|
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
const utcDate = '2023-06-22';
|
const utcDate = '2023-06-22';
|
||||||
const utcTime = '27:00';
|
const utcTime = '27:00';
|
||||||
const parisTime = timeConverter.utcStringDateTimeToLocalIsoString(
|
expect(() => {
|
||||||
|
timeConverter.utcStringDateTimeToLocalIsoString(
|
||||||
utcDate,
|
utcDate,
|
||||||
utcTime,
|
utcTime,
|
||||||
'Europe/Paris',
|
'Europe/Paris',
|
||||||
);
|
);
|
||||||
expect(parisTime).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it('should return undefined if time is undefined', () => {
|
it('should throw an error if timezone is invalid', () => {
|
||||||
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', () => {
|
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
const utcDate = '2023-06-22';
|
const utcDate = '2023-06-22';
|
||||||
const utcTime = '07:00';
|
const utcTime = '07:00';
|
||||||
const parisTime = timeConverter.utcStringDateTimeToLocalIsoString(
|
expect(() => {
|
||||||
|
timeConverter.utcStringDateTimeToLocalIsoString(
|
||||||
utcDate,
|
utcDate,
|
||||||
utcTime,
|
utcTime,
|
||||||
'Foo/Bar',
|
'Foo/Bar',
|
||||||
);
|
);
|
||||||
expect(parisTime).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -371,29 +262,17 @@ describe('Time Converter', () => {
|
||||||
timeConverter.utcUnixEpochDayFromTime('16:00', 'Pacific/Tahiti'),
|
timeConverter.utcUnixEpochDayFromTime('16:00', 'Pacific/Tahiti'),
|
||||||
).toBe(5);
|
).toBe(5);
|
||||||
});
|
});
|
||||||
it('should return undefined if time is invalid', () => {
|
it('should throw an error if time is invalid', () => {
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
expect(
|
expect(() => {
|
||||||
timeConverter.utcUnixEpochDayFromTime('28:00', 'Europe/Paris'),
|
timeConverter.utcUnixEpochDayFromTime('28:00', 'Europe/Paris');
|
||||||
).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it('should return undefined if time is undefined', () => {
|
it('should throw an error if timezone is invalid', () => {
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
expect(
|
expect(() => {
|
||||||
timeConverter.utcUnixEpochDayFromTime(undefined, 'Europe/Paris'),
|
timeConverter.utcUnixEpochDayFromTime('12:00', 'Foo/Bar');
|
||||||
).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -416,29 +295,17 @@ describe('Time Converter', () => {
|
||||||
timeConverter.localUnixEpochDayFromTime('05:00', 'Pacific/Tahiti'),
|
timeConverter.localUnixEpochDayFromTime('05:00', 'Pacific/Tahiti'),
|
||||||
).toBe(3);
|
).toBe(3);
|
||||||
});
|
});
|
||||||
it('should return undefined if time is invalid', () => {
|
it('should throw an error if time is invalid', () => {
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
expect(
|
expect(() => {
|
||||||
timeConverter.localUnixEpochDayFromTime('28:00', 'Europe/Paris'),
|
timeConverter.localUnixEpochDayFromTime('28:00', 'Europe/Paris');
|
||||||
).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it('should return undefined if time is undefined', () => {
|
it('should throw an error if timezone is invalid', () => {
|
||||||
const timeConverter: TimeConverter = new TimeConverter();
|
const timeConverter: TimeConverter = new TimeConverter();
|
||||||
expect(
|
expect(() => {
|
||||||
timeConverter.localUnixEpochDayFromTime(undefined, 'Europe/Paris'),
|
timeConverter.localUnixEpochDayFromTime('12:00', 'Foo/Bar');
|
||||||
).toBeUndefined();
|
}).toThrow();
|
||||||
});
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue