matcher/old/modules/ad/tests/unit/domain/time-converter.spec.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

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);
});
2023-05-22 09:25:09 +00:00
it('should return undefined when trying to convert a Europe/Paris datetime to utc datetime without a valid date', () => {
2023-05-02 15:26:04 +00:00
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();
2023-05-22 09:25:09 +00:00
});
it('should return undefined when trying to convert a Europe/Paris datetime to utc datetime without a valid time', () => {
2023-05-02 15:26:04 +00:00
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();
2023-05-22 09:25:09 +00:00
});
it('should return undefined when trying to convert a datetime to utc datetime without a valid timezone', () => {
2023-05-02 15:26:04 +00:00
expect(
2023-05-11 15:47:55 +00:00
TimeConverter.toUtcDatetime(
2023-05-22 09:25:09 +00:00
new Date('2023-12-01'),
2023-05-11 15:47:55 +00:00
'07:00',
'OlympusMons/Mars',
),
2023-05-02 15:26:04 +00:00
).toBeUndefined();
});
});