Skip to content

Commit 5923bc5

Browse files
committed
feat: add JSDoc types
so the project can be statically analysed by TypeScript
1 parent 2de95b6 commit 5923bc5

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

parse.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Times are parsed as UTC if no offset is specified
1+
/**
2+
* _Times are parsed as UTC if no offset is specified_
3+
*/
24
export class IsoDateParts {
35
static DEFAULT_TIMEZONE_OFFSET = {
46
hours: 0,
@@ -27,6 +29,7 @@ export class IsoDateParts {
2729
};
2830
}
2931

32+
/** @param {RegExpMatchArray} match */
3033
static getByDateTime(match) {
3134
let offset = this.getTimezoneOffset(match[8]);
3235

@@ -42,6 +45,7 @@ export class IsoDateParts {
4245
};
4346
}
4447

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 */
4549
static getParts(str) {
4650
let dateMatch = str.match(this.FULL_DATE_REGEX);
4751
if(dateMatch) {
@@ -62,6 +66,24 @@ export class IsoDateParts {
6266
}
6367

6468
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 */
6587
static parse(str) {
6688
let parts = IsoDateParts.getParts(str);
6789
if(parts) {
@@ -75,11 +97,22 @@ export class IsoDate {
7597
throw new Error(`Unsupported date format: ${str}`);
7698
}
7799

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+
*/
78110
constructor(parts) {
79-
// parts.day, parts.year, parts.month, parts.week
111+
// parts.day, parts.year, parts.month
80112
Object.assign(this, parts);
81113
}
82114

115+
/** @returns {[number, number, number, number, number, number, number]} */
83116
getArgs() {
84117
return [this.year, this.month, this.day, this.hours, this.minutes, this.seconds, this.milliseconds];
85118
}
@@ -97,6 +130,7 @@ export class IsoDate {
97130
}
98131
}
99132

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 */
100134
export function parse(str) {
101135
return IsoDate.parse(str);
102136
}

0 commit comments

Comments
 (0)