55 formatNumber ,
66 formatDateForLocale ,
77 getTime ,
8+ getLocalTime ,
89 FUTURE ,
910 PAST ,
1011 getUtcStartOfDay ,
@@ -198,21 +199,37 @@ describe('formatDateForLocale', () => {
198199} ) ;
199200
200201describe ( 'getTime' , ( ) => {
201- describe ( 'valid ISO dates (UTC)' , ( ) => {
202+ describe ( 'valid ISO dates (UTC time )' , ( ) => {
202203 it ( 'returns correct UTC time (HH:mm)' , ( ) => {
203- expect ( getTime ( '2026-02-17T09:55:24.190Z' ) ) . toBe ( '09:55' ) ;
204+ const testDate = '2026-02-17T09:55:24.190Z' ;
205+ const date = new Date ( testDate ) ;
206+ const expectedHours = date . getUTCHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
207+ const expectedMinutes = date . getUTCMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
208+ expect ( getTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
204209 } ) ;
205210
206211 it ( 'pads single digit hours and minutes' , ( ) => {
207- expect ( getTime ( '2026-02-17T05:07:00.000Z' ) ) . toBe ( '05:07' ) ;
212+ const testDate = '2026-02-17T05:07:00.000Z' ;
213+ const date = new Date ( testDate ) ;
214+ const expectedHours = date . getUTCHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
215+ const expectedMinutes = date . getUTCMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
216+ expect ( getTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
208217 } ) ;
209218
210219 it ( 'handles midnight correctly' , ( ) => {
211- expect ( getTime ( '2026-02-17T00:00:00.000Z' ) ) . toBe ( '00:00' ) ;
220+ const testDate = '2026-02-17T00:00:00.000Z' ;
221+ const date = new Date ( testDate ) ;
222+ const expectedHours = date . getUTCHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
223+ const expectedMinutes = date . getUTCMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
224+ expect ( getTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
212225 } ) ;
213226
214227 it ( 'handles end of day correctly' , ( ) => {
215- expect ( getTime ( '2026-02-17T23:59:59.999Z' ) ) . toBe ( '23:59' ) ;
228+ const testDate = '2026-02-17T23:59:59.999Z' ;
229+ const date = new Date ( testDate ) ;
230+ const expectedHours = date . getUTCHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
231+ const expectedMinutes = date . getUTCMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
232+ expect ( getTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
216233 } ) ;
217234 } ) ;
218235
@@ -239,6 +256,64 @@ describe('getTime', () => {
239256 } ) ;
240257} ) ;
241258
259+ describe ( 'getLocalTime' , ( ) => {
260+ describe ( 'valid ISO dates (local time)' , ( ) => {
261+ it ( 'returns correct local time (HH:mm)' , ( ) => {
262+ const testDate = '2026-02-17T09:55:24.190Z' ;
263+ const date = new Date ( testDate ) ;
264+ const expectedHours = date . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
265+ const expectedMinutes = date . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
266+ expect ( getLocalTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
267+ } ) ;
268+
269+ it ( 'pads single digit hours and minutes' , ( ) => {
270+ const testDate = '2026-02-17T05:07:00.000Z' ;
271+ const date = new Date ( testDate ) ;
272+ const expectedHours = date . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
273+ const expectedMinutes = date . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
274+ expect ( getLocalTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
275+ } ) ;
276+
277+ it ( 'handles midnight correctly' , ( ) => {
278+ const testDate = '2026-02-17T00:00:00.000Z' ;
279+ const date = new Date ( testDate ) ;
280+ const expectedHours = date . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
281+ const expectedMinutes = date . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
282+ expect ( getLocalTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
283+ } ) ;
284+
285+ it ( 'handles end of day correctly' , ( ) => {
286+ const testDate = '2026-02-17T23:59:59.999Z' ;
287+ const date = new Date ( testDate ) ;
288+ const expectedHours = date . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
289+ const expectedMinutes = date . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
290+ expect ( getLocalTime ( testDate ) ) . toBe ( `${ expectedHours } :${ expectedMinutes } ` ) ;
291+ } ) ;
292+ } ) ;
293+
294+ describe ( 'invalid input' , ( ) => {
295+ it ( 'returns EMPTY_STRING for empty string' , ( ) => {
296+ expect ( getLocalTime ( '' ) ) . toBe ( EMPTY_STRING ) ;
297+ } ) ;
298+
299+ it ( 'returns EMPTY_STRING for invalid date string' , ( ) => {
300+ expect ( getLocalTime ( 'not-a-date' ) ) . toBe ( EMPTY_STRING ) ;
301+ } ) ;
302+
303+ it ( 'returns EMPTY_STRING for malformed ISO string' , ( ) => {
304+ expect ( getLocalTime ( '2026-99-99T99:99:99Z' ) ) . toBe ( EMPTY_STRING ) ;
305+ } ) ;
306+
307+ it ( 'returns EMPTY_STRING for null (runtime edge case)' , ( ) => {
308+ expect ( getLocalTime ( null as unknown as string ) ) . toBe ( EMPTY_STRING ) ;
309+ } ) ;
310+
311+ it ( 'returns EMPTY_STRING for undefined (runtime edge case)' , ( ) => {
312+ expect ( getLocalTime ( undefined as unknown as string ) ) . toBe ( EMPTY_STRING ) ;
313+ } ) ;
314+ } ) ;
315+ } ) ;
316+
242317describe ( 'Date Utilities' , ( ) => {
243318 describe ( 'getUtcStartOfDay' , ( ) => {
244319 it ( 'should return UTC midnight for a given date' , ( ) => {
@@ -428,8 +503,12 @@ describe('formatDateForChat', () => {
428503 describe ( 'within last 24 hours' , ( ) => {
429504 it ( 'returns time (HH:mm)' , ( ) => {
430505 const iso = '2026-03-10T09:30:00Z' ;
506+ const date = new Date ( iso ) ;
507+ const expectedHours = date . getHours ( ) . toString ( ) . padStart ( 2 , '0' ) ;
508+ const expectedMinutes = date . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
509+ const expectedTime = `${ expectedHours } :${ expectedMinutes } ` ;
431510
432- expect ( formatDateForChat ( iso , locale ) ) . toBe ( '09:30' ) ;
511+ expect ( formatDateForChat ( iso , locale ) ) . toBe ( expectedTime ) ;
433512 } ) ;
434513 } ) ;
435514
0 commit comments