@@ -6,41 +6,6 @@ import {
66
77import type { Event } from '../../../../src/types/index.d.ts' ;
88
9- describe ( 'mergeDateAndTimeToISOString' , ( ) => {
10- it ( 'merges date and time (HH:mm) to ISO string in UTC' , ( ) => {
11- const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ; // 2023-06-01T00:00:00.000Z
12- const time = '14:30' ;
13- const result = mergeDateAndTimeToISOString ( date , time ) ;
14- expect ( result ) . toBe ( '2023-06-01T14:30:00.000Z' ) ;
15- } ) ;
16-
17- it ( 'merges date and time (HH:mm:ss) to ISO string in UTC' , ( ) => {
18- const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
19- const time = '14:30:15' ;
20- const result = mergeDateAndTimeToISOString ( date , time ) ;
21- expect ( result ) . toBe ( '2023-06-01T14:30:15.000Z' ) ;
22- } ) ;
23-
24- it ( 'merges date and time (HH:mm:ss.sss) to ISO string in UTC' , ( ) => {
25- const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
26- const time = '14:30:15.123' ;
27- const result = mergeDateAndTimeToISOString ( date , time ) ;
28- expect ( result ) . toBe ( '2023-06-01T14:30:15.123Z' ) ;
29- } ) ;
30-
31- it ( 'ignores timezone offset in time string' , ( ) => {
32- const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
33- const time = '14:30:15.123+02:00' ;
34- const result = mergeDateAndTimeToISOString ( date , time ) ;
35- expect ( result ) . toBe ( '2023-06-01T14:30:15.123Z' ) ;
36- } ) ;
37-
38- it ( 'throws error for invalid time format' , ( ) => {
39- const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
40- expect ( ( ) => mergeDateAndTimeToISOString ( date , 'badtime' ) ) . toThrow ( ) ;
41- } ) ;
42- } ) ;
43-
449describe ( 'dateTimePartsToEvent' , ( ) => {
4510 it ( 'returns start_datetime and end_datetime when times are provided' , ( ) => {
4611 const startDate = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
@@ -149,3 +114,53 @@ describe('eventToDateTimeParts', () => {
149114 } ) ;
150115 } ) ;
151116} ) ;
117+
118+ describe ( 'mergeDateAndTimeToISOString' , ( ) => {
119+ it ( 'merges date and time (HH:mm) to ISO string in UTC' , ( ) => {
120+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ; // 2023-06-01T00:00:00.000Z
121+ const time = '14:30' ;
122+ const result = mergeDateAndTimeToISOString ( date , time ) ;
123+ expect ( result ) . toBe ( '2023-06-01T14:30:00.000Z' ) ;
124+ } ) ;
125+
126+ it ( 'merges date and time (HH:mm:ss) to ISO string in UTC' , ( ) => {
127+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
128+ const time = '14:30:15' ;
129+ const result = mergeDateAndTimeToISOString ( date , time ) ;
130+ expect ( result ) . toBe ( '2023-06-01T14:30:15.000Z' ) ;
131+ } ) ;
132+
133+ it ( 'merges date and time (HH:mm:ss.sss) to ISO string in UTC' , ( ) => {
134+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
135+ const time = '14:30:15.123' ;
136+ const result = mergeDateAndTimeToISOString ( date , time ) ;
137+ expect ( result ) . toBe ( '2023-06-01T14:30:15.123Z' ) ;
138+ } ) ;
139+
140+ it ( 'ignores timezone offset in time string' , ( ) => {
141+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
142+ const time = '14:30:15.123+02:00' ;
143+ const result = mergeDateAndTimeToISOString ( date , time ) ;
144+ expect ( result ) . toBe ( '2023-06-01T14:30:15.123Z' ) ;
145+ } ) ;
146+
147+ it ( 'throws error for invalid time format' , ( ) => {
148+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
149+ expect ( ( ) => mergeDateAndTimeToISOString ( date , 'badtime' ) ) . toThrow ( ) ;
150+ } ) ;
151+
152+ it ( 'throws error for non-numeric hour' , ( ) => {
153+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
154+ expect ( ( ) => mergeDateAndTimeToISOString ( date , 'xx:30' ) ) . toThrow ( 'Invalid numeric values in time: xx:30' ) ;
155+ } ) ;
156+
157+ it ( 'throws error for non-numeric minute' , ( ) => {
158+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
159+ expect ( ( ) => mergeDateAndTimeToISOString ( date , '14:xx' ) ) . toThrow ( 'Invalid numeric values in time: 14:xx' ) ;
160+ } ) ;
161+
162+ it ( 'throws error for non-numeric second' , ( ) => {
163+ const date = new Date ( Date . UTC ( 2023 , 5 , 1 ) ) ;
164+ expect ( ( ) => mergeDateAndTimeToISOString ( date , '14:30:xx' ) ) . toThrow ( 'Invalid numeric values in time: 14:30:xx' ) ;
165+ } ) ;
166+ } ) ;
0 commit comments