File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// convert HH:MM:SS or MM:SS to milliseconds
2- export function hmsToMilliSeconds ( str : number | string | undefined ) : number {
3- if ( typeof str == 'undefined' || str === '' || isNaN ( Number ( str ) ) ) return NaN ;
2+ export function hmsToMilliSeconds ( str : number | string | null | undefined ) : number {
3+ if ( typeof str == 'undefined' || str === null || str === '' ) return NaN ;
44 if ( typeof str == 'number' ) return str ;
55 const t = str . split ( ':' ) ;
66 let s = 0 ;
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest' ;
2+
3+ import { hmsToMilliSeconds } from '../../src/lib/shared/time-functions' ;
4+
5+ describe ( 'hmsToMilliSeconds' , ( ) => {
6+ it ( 'converts MM:SS durations to milliseconds' , ( ) => {
7+ expect ( hmsToMilliSeconds ( '06:50' ) ) . toBe ( 410_000 ) ;
8+ } ) ;
9+
10+ it ( 'converts HH:MM:SS durations to milliseconds' , ( ) => {
11+ expect ( hmsToMilliSeconds ( '1:02:03' ) ) . toBe ( 3_723_000 ) ;
12+ } ) ;
13+
14+ it ( 'keeps numeric millisecond durations unchanged' , ( ) => {
15+ expect ( hmsToMilliSeconds ( 410_000 ) ) . toBe ( 410_000 ) ;
16+ } ) ;
17+
18+ it ( 'returns NaN for missing or empty durations' , ( ) => {
19+ expect ( hmsToMilliSeconds ( undefined ) ) . toBeNaN ( ) ;
20+ expect ( hmsToMilliSeconds ( null ) ) . toBeNaN ( ) ;
21+ expect ( hmsToMilliSeconds ( '' ) ) . toBeNaN ( ) ;
22+ expect ( hmsToMilliSeconds ( NaN ) ) . toBeNaN ( ) ;
23+ expect ( hmsToMilliSeconds ( 'NaN' ) ) . toBeNaN ( ) ;
24+ expect ( hmsToMilliSeconds ( 'random text' ) ) . toBeNaN ( ) ;
25+ } ) ;
26+ } ) ;
You can’t perform that action at this time.
0 commit comments