2023-05-02 15:26:04 +00:00
|
|
|
import { TimeConverter } from '../../../domain/entities/time-converter';
|
|
|
|
|
|
|
|
describe('TimeConverter', () => {
|
|
|
|
it('should be defined', () => {
|
|
|
|
expect(new TimeConverter()).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should convert a Europe/Paris datetime to utc datetime', () => {
|
|
|
|
expect(
|
|
|
|
TimeConverter.toUtcDatetime(
|
2023-05-11 15:47:55 +00:00
|
|
|
new Date('2023-05-01'),
|
2023-05-02 15:26:04 +00:00
|
|
|
'07:00',
|
|
|
|
'Europe/Paris',
|
|
|
|
).getUTCHours(),
|
|
|
|
).toBe(6);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return undefined when trying to convert a Europe/Paris datetime to utc datetime without a valid date, time or timezone', () => {
|
|
|
|
expect(
|
|
|
|
TimeConverter.toUtcDatetime(undefined, '07:00', 'Europe/Paris'),
|
|
|
|
).toBeUndefined();
|
|
|
|
expect(
|
2023-05-11 15:47:55 +00:00
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
new Date('2023-13-01'),
|
|
|
|
'07:00',
|
|
|
|
'Europe/Paris',
|
|
|
|
),
|
2023-05-02 15:26:04 +00:00
|
|
|
).toBeUndefined();
|
|
|
|
expect(
|
2023-05-11 15:47:55 +00:00
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
new Date('2023-05-01'),
|
|
|
|
undefined,
|
|
|
|
'Europe/Paris',
|
|
|
|
),
|
2023-05-02 15:26:04 +00:00
|
|
|
).toBeUndefined();
|
|
|
|
expect(
|
2023-05-11 15:47:55 +00:00
|
|
|
TimeConverter.toUtcDatetime(new Date('2023-05-01'), 'a', 'Europe/Paris'),
|
2023-05-02 15:26:04 +00:00
|
|
|
).toBeUndefined();
|
|
|
|
expect(
|
2023-05-11 15:47:55 +00:00
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
new Date('2023-13-01'),
|
|
|
|
'07:00',
|
|
|
|
'OlympusMons/Mars',
|
|
|
|
),
|
2023-05-02 15:26:04 +00:00
|
|
|
).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|