Skip to content

Commit a611347

Browse files
committed
fix linting, add some comments
Signed-off-by: flakey5 <[email protected]>
1 parent ca64560 commit a611347

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/utils/http-date.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
/**
2+
* Valid months that are allowed to be in an IMF date
3+
*/
14
const IMF_DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
5+
6+
/**
7+
* Specific locations that are expected to be spaces in an IMF date
8+
*/
29
const IMF_SPACES = [4, 7, 11, 16, 25];
10+
11+
/**
12+
* Valid months that are allowed to be in an IMF date
13+
*/
314
const IMF_MONTHS = [
415
'jan',
516
'feb',
@@ -14,10 +25,20 @@ const IMF_MONTHS = [
1425
'nov',
1526
'dec',
1627
];
28+
29+
/**
30+
* Specific locations that are expected to be colons in an IMF date
31+
*/
1732
const IMF_COLONS = [19, 22];
1833

34+
/**
35+
* Specific locations that are expected to be spaces in an asctime() date
36+
*/
1937
const ASCTIME_SPACES = [3, 7, 10, 19];
2038

39+
/**
40+
* Valid days allowed in an RF850 date
41+
*/
2142
const RFC850_DAYS = [
2243
'monday',
2344
'tuesday',
@@ -39,7 +60,7 @@ export function parseHttpDate(
3960
// Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
4061
// Sunday, 06-Nov-94 08:49:37 GMT ; obsolete RFC 850 format
4162

42-
if (!date) {
63+
if (date === null) {
4364
return undefined;
4465
}
4566

@@ -68,12 +89,14 @@ function parseImfDate(date: string): Date | undefined {
6889
return undefined;
6990
}
7091

92+
// Ensure there are spaces in the expected locations
7193
for (const spaceInx of IMF_SPACES) {
7294
if (date[spaceInx] !== ' ') {
7395
return undefined;
7496
}
7597
}
7698

99+
// Ensure there are colons in the expected locations
77100
for (const colonIdx of IMF_COLONS) {
78101
if (date[colonIdx] !== ':') {
79102
return undefined;
@@ -134,6 +157,7 @@ function parseAscTimeDate(date: string): Date | undefined {
134157
return undefined;
135158
}
136159

160+
// Ensure there are spaces in the expected locations
137161
for (const spaceIdx of ASCTIME_SPACES) {
138162
if (date[spaceIdx] !== ' ') {
139163
return undefined;
@@ -206,6 +230,7 @@ function parseRfc850Date(date: string, now = new Date()): Date | undefined {
206230
return undefined;
207231
}
208232

233+
// Ensure there are spaces, dashes, and colons in the expected locations
209234
if (
210235
date[commaIndex + 1] !== ' ' ||
211236
date[commaIndex + 4] !== '-' ||

0 commit comments

Comments
 (0)