@@ -7,7 +7,7 @@ export const slugify = hashids.encode.bind(hashids);
77/*
88 * Several types of permalinks are supported, in order of preference:
99 * /#/<channel>/<hashid> - see https://hashids.org/
10- * /#/<channel>/YYYY-MM-DD
10+ * /#/<channel>/YYYY-MM-DD - parsed as YYYY-MM-DDT00:00:00
1111 * /#/<channel>/YYYY-MM-DDTHH:MM:SS
1212 *
1313 * Try to parse the timestamp, first to succeed wins.
@@ -17,18 +17,19 @@ export const slugify = hashids.encode.bind(hashids);
1717export function oportunisticParsePemalink ( permalink : string ) : number | null {
1818 // try hashids first
1919 try {
20- let t = hashids . decode ( permalink ) ;
20+ const t = hashids . decode ( permalink ) ;
2121 if ( t . length > 0 ) return t [ 0 ] as number ;
2222 } catch { } // noop - obviously not a hashid
2323
24- // try a Date second , for ex. '2020-02-03'
25- // since for this permalink makes the most sense for the users local timezone,
26- // add the 0th hour to the string, otherwise it would be parsed as UTC timezone
27- let date = Date . parse ( permalink + "T00:00:00" ) ;
24+ // next, assume it's a Date, for ex. '2020-02-03'
25+ // a string like that is parsed as UTC, so we add "T00:00:00" to it
26+ // assuming the user wanted the begining of the day in their local timezone
27+ const date = Date . parse ( permalink + "T00:00:00" ) ;
2828 if ( ! Number . isNaN ( date ) ) return date / 1000 ;
2929
30- // if all failed, it might be just a timestamp or full DateTime
31- let datetime = Date . parse ( permalink ) ;
30+ // if that failed, then it might be some dateString
31+ // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
32+ const datetime = Date . parse ( permalink ) ;
3233 if ( ! Number . isNaN ( datetime ) ) return datetime / 1000 ;
3334
3435 console . warn ( "permalink couldn't be parsed:" , permalink ) ;
0 commit comments