@@ -7,7 +7,7 @@ export const slugify = hashids.encode.bind(hashids);
7
7
/*
8
8
* Several types of permalinks are supported, in order of preference:
9
9
* /#/<channel>/<hashid> - see https://hashids.org/
10
- * /#/<channel>/YYYY-MM-DD
10
+ * /#/<channel>/YYYY-MM-DD - parsed as YYYY-MM-DDT00:00:00
11
11
* /#/<channel>/YYYY-MM-DDTHH:MM:SS
12
12
*
13
13
* Try to parse the timestamp, first to succeed wins.
@@ -17,18 +17,19 @@ export const slugify = hashids.encode.bind(hashids);
17
17
export function oportunisticParsePemalink ( permalink : string ) : number | null {
18
18
// try hashids first
19
19
try {
20
- let t = hashids . decode ( permalink ) ;
20
+ const t = hashids . decode ( permalink ) ;
21
21
if ( t . length > 0 ) return t [ 0 ] as number ;
22
22
} catch { } // noop - obviously not a hashid
23
23
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" ) ;
28
28
if ( ! Number . isNaN ( date ) ) return date / 1000 ;
29
29
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 ) ;
32
33
if ( ! Number . isNaN ( datetime ) ) return datetime / 1000 ;
33
34
34
35
console . warn ( "permalink couldn't be parsed:" , permalink ) ;
0 commit comments