This repository was archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix DateParam.parser #74
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import { DateRange } from '~/fiscal-periods/date-range' | ||
|
|
||
| test('diff', () => { | ||
| expect(new DateRange(new Date(2020, 9, 6), new Date(2021, 9, 6)).diff()).toEqual(365) | ||
| expect(new DateRange(new Date(2020, 9, 6), new Date(2020, 9, 7)).diff()).toEqual(1) | ||
| expect(new DateRange(new Date(2020, 9, 6), new Date(2020, 9, 6)).diff()).toEqual(0) | ||
| expect(new DateRange(new Date(2020, 9, 6), new Date(2020, 9, 5)).diff()).toEqual(-1) | ||
| expect(new DateRange(new Date(2020, 9, 6), new Date(2019, 9, 6)).diff()).toEqual(-366) | ||
| expect(new DateRange(new Date('2020-09-06'), new Date('2021-09-06')).diff()).toEqual(365) | ||
| expect(new DateRange(new Date('2020-09-06'), new Date('2020-09-07')).diff()).toEqual(1) | ||
| expect(new DateRange(new Date('2020-09-06'), new Date('2020-09-06')).diff()).toEqual(0) | ||
| expect(new DateRange(new Date('2020-09-06'), new Date('2020-09-05')).diff()).toEqual(-1) | ||
| expect(new DateRange(new Date('2020-09-06'), new Date('2019-09-06')).diff()).toEqual(-366) | ||
| }) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
バグ修正の本体です。2つのバグがありました。
new Date()の引数はnew Date(year, month, day)ではなくnew Date(year, monthIndex, day)なので、指定月-1を渡すのが正しいのだが、そのまま月を渡していたnew Date(year, monthIndex, day)形式でDateを生成すると自動的にタイムゾーンがGMT+0900 (Japan Standard Time)として解釈されるものの、toISOString()時にT15:00:00.000ZとUTCに自動的に変換されてしまうために、ロケールが日本の場合には-1日されて解釈されてしまう (?)上記の問題はどちらも
new Date('YYYY-MM-DD')のように文字列型で渡すことで解決したので、そのようにしています。参考: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字列渡すほうがむしろ安全っていうのがちょい残念だけど、なるほど。
真ん中が
monthIndexだったの、見るたびに「あーそうだった」ってなるな・・・