-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle local timezone and UTC respectively * Add test for local time TZ was added because the test would fail depending on CI and also the developer's environment * Setup GitHub Actions test
- Loading branch information
Showing
8 changed files
with
131 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export default class LocalDate { | ||
constructor() { | ||
this.date = new Date(Date.now()) | ||
} | ||
|
||
getFullYear() { | ||
return this.date.getFullYear() | ||
} | ||
|
||
getMonth() { | ||
return this.date.getMonth() | ||
} | ||
|
||
getWeek() { | ||
return this.getWeek() | ||
} | ||
|
||
getDate() { | ||
return this.date.getDate() | ||
} | ||
|
||
getWeek() { | ||
const d = new Date( | ||
this.date.getFullYear(), | ||
this.date.getMonth(), | ||
this.date.getDate() | ||
) | ||
const daynum = d.getDay() || 7 | ||
|
||
d.setDate(d.getDate() + 4 - daynum) | ||
|
||
const yearstart = new Date(d.getFullYear(), 0, 1) | ||
|
||
return Math.ceil(((d - yearstart) / 86400000 + 1) / 7) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export default class UtcDate { | ||
constructor() { | ||
this.date = new Date(Date.now()) | ||
} | ||
|
||
getFullYear() { | ||
return this.date.getUTCFullYear() | ||
} | ||
|
||
getMonth() { | ||
return this.date.getUTCMonth() | ||
} | ||
|
||
getWeek() { | ||
return this.getUTCWeek() | ||
} | ||
|
||
getDate() { | ||
return this.date.getUTCDate() | ||
} | ||
|
||
getUTCWeek() { | ||
const d = new Date( | ||
Date.UTC( | ||
this.date.getFullYear(), | ||
this.date.getMonth(), | ||
this.date.getDate() | ||
) | ||
); | ||
const daynum = d.getUTCDay() || 7 | ||
|
||
d.setUTCDate(d.getUTCDate() + 4 - daynum) | ||
|
||
const yearstart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1)) | ||
|
||
return Math.ceil(((d - yearstart) / 86400000 + 1) / 7) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters