1
- // Times are parsed as UTC if no offset is specified
1
+ /**
2
+ * _Times are parsed as UTC if no offset is specified_
3
+ */
2
4
export class IsoDateParts {
3
5
static DEFAULT_TIMEZONE_OFFSET = {
4
6
hours : 0 ,
@@ -27,6 +29,7 @@ export class IsoDateParts {
27
29
} ;
28
30
}
29
31
32
+ /** @param {RegExpMatchArray } match */
30
33
static getByDateTime ( match ) {
31
34
let offset = this . getTimezoneOffset ( match [ 8 ] ) ;
32
35
@@ -42,6 +45,7 @@ export class IsoDateParts {
42
45
} ;
43
46
}
44
47
48
+ /** @param {string } str An [RFC 9557](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#rfc_9557_format)-compatible string */
45
49
static getParts ( str ) {
46
50
let dateMatch = str . match ( this . FULL_DATE_REGEX ) ;
47
51
if ( dateMatch ) {
@@ -62,6 +66,24 @@ export class IsoDateParts {
62
66
}
63
67
64
68
export class IsoDate {
69
+ /** @type {number } */
70
+ year ;
71
+ /** @type {number } */
72
+ month ;
73
+ /** @type {number } */
74
+ day ;
75
+ /** @type {number } */
76
+ hours ;
77
+ /** @type {number } */
78
+ minutes ;
79
+ /** @type {number } */
80
+ seconds ;
81
+ /** @type {number } */
82
+ milliseconds ;
83
+ /** @type {string } */
84
+ source ;
85
+
86
+ /** @param {string } str An [RFC 9557](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#rfc_9557_format)-compatible string */
65
87
static parse ( str ) {
66
88
let parts = IsoDateParts . getParts ( str ) ;
67
89
if ( parts ) {
@@ -75,11 +97,22 @@ export class IsoDate {
75
97
throw new Error ( `Unsupported date format: ${ str } ` ) ;
76
98
}
77
99
100
+ /**
101
+ * @param {object } parts
102
+ * @param {number } parts.year
103
+ * @param {number } parts.month
104
+ * @param {number } parts.day
105
+ * @param {number } parts.hours
106
+ * @param {number } parts.minutes
107
+ * @param {number } parts.seconds
108
+ * @param {number } parts.milliseconds
109
+ */
78
110
constructor ( parts ) {
79
- // parts.day, parts.year, parts.month, parts.week
111
+ // parts.day, parts.year, parts.month
80
112
Object . assign ( this , parts ) ;
81
113
}
82
114
115
+ /** @returns {[number, number, number, number, number, number, number] } */
83
116
getArgs ( ) {
84
117
return [ this . year , this . month , this . day , this . hours , this . minutes , this . seconds , this . milliseconds ] ;
85
118
}
@@ -97,6 +130,7 @@ export class IsoDate {
97
130
}
98
131
}
99
132
133
+ /** @param {string } str An [RFC 9557](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#rfc_9557_format)-compatible string */
100
134
export function parse ( str ) {
101
135
return IsoDate . parse ( str ) ;
102
136
}
0 commit comments