-
Notifications
You must be signed in to change notification settings - Fork 28
[210_15] srfi-19 time-utc date相互转化实现 #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # [210_15] srfi-19 time-utc date相互转化实现 | ||
|
|
||
| ## 添加 srfi-19 time-utc date相互转化实现 | ||
|
|
||
| ## 如何测试 | ||
|
|
||
| ```shell | ||
| # 可能需要清除缓存 | ||
| # rm .xmake/ build/ -r | ||
| xmake f -vyD | ||
| xmake b goldfish | ||
| ./bin/goldfish tests/goldfish/liii/time-test.scm | ||
| ``` | ||
|
|
||
|
|
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 |
|---|---|---|
|
|
@@ -807,6 +807,108 @@ wrong-type-arg | |
| (check-true (undefined? (date-year (make-time TIME-UTC 0 0)))) | ||
| (check-catch 'wrong-type-arg (date-zone-offset #f)) | ||
|
|
||
| ;; ==================== | ||
| ;; Time/Date Converters | ||
| ;; ==================== | ||
|
|
||
| #| | ||
| time-utc->date | ||
| 将 TIME-UTC 时间对象转换为日期对象。 | ||
|
|
||
| date->time-utc | ||
| 将日期对象转换为 TIME-UTC 时间对象。 | ||
| |# | ||
|
Comment on lines
+814
to
+820
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 写得太简略了。另外 规范中要求使用本地时区,虽然现在没有做接口(得到当前时区),但是这一点要明确写出来。留个 TODO 之后需要实现 |
||
|
|
||
| ;; time-utc->date basic (UTC) | ||
| (let* ((t (make-time TIME-UTC 0 0)) | ||
| (d (time-utc->date t 0))) | ||
| (check (date-year d) => 1970) | ||
| (check (date-month d) => 1) | ||
| (check (date-day d) => 1) | ||
| (check (date-hour d) => 0) | ||
| (check (date-minute d) => 0) | ||
| (check (date-second d) => 0) | ||
| (check (date-zone-offset d) => 0)) | ||
|
|
||
| ;; time-utc->date with positive tz offset (+8) | ||
| (let* ((t (make-time TIME-UTC 0 0)) | ||
| (d (time-utc->date t 28800))) | ||
| (check (date-year d) => 1970) | ||
| (check (date-month d) => 1) | ||
| (check (date-day d) => 1) | ||
| (check (date-hour d) => 8) | ||
| (check (date-minute d) => 0) | ||
| (check (date-second d) => 0) | ||
| (check (date-zone-offset d) => 28800)) | ||
|
|
||
| ;; time-utc->date with negative tz offset (-1 hour) | ||
| (let* ((t (make-time TIME-UTC 0 0)) | ||
| (d (time-utc->date t -3600))) | ||
| (check (date-year d) => 1969) | ||
| (check (date-month d) => 12) | ||
| (check (date-day d) => 31) | ||
| (check (date-hour d) => 23) | ||
| (check (date-minute d) => 0) | ||
| (check (date-second d) => 0) | ||
| (check (date-zone-offset d) => -3600)) | ||
|
|
||
| ;; time-utc->date before 1970 | ||
| (let* ((t (make-time TIME-UTC 0 -1)) | ||
| (d (time-utc->date t 0))) | ||
| (check (date-year d) => 1969) | ||
| (check (date-month d) => 12) | ||
| (check (date-day d) => 31) | ||
| (check (date-hour d) => 23) | ||
| (check (date-minute d) => 59) | ||
| (check (date-second d) => 59)) | ||
|
|
||
| ;; time-utc->date negative day boundaries | ||
| (let* ((t (make-time TIME-UTC 0 -86400)) | ||
| (d (time-utc->date t 0))) | ||
| (check (date-year d) => 1969) | ||
| (check (date-month d) => 12) | ||
| (check (date-day d) => 31) | ||
| (check (date-hour d) => 0) | ||
| (check (date-minute d) => 0) | ||
| (check (date-second d) => 0)) | ||
|
|
||
| (let* ((t (make-time TIME-UTC 0 -86401)) | ||
| (d (time-utc->date t 0))) | ||
| (check (date-year d) => 1969) | ||
| (check (date-month d) => 12) | ||
| (check (date-day d) => 30) | ||
| (check (date-hour d) => 23) | ||
| (check (date-minute d) => 59) | ||
| (check (date-second d) => 59)) | ||
|
|
||
| ;; date->time-utc basic | ||
| (let* ((d (make-date 0 0 0 8 1 1 1970 28800)) | ||
| (t (date->time-utc d))) | ||
| (check (time-type t) => TIME-UTC) | ||
| (check (time-second t) => 0) | ||
| (check (time-nanosecond t) => 0)) | ||
|
|
||
| ;; round-trip date -> time -> date with same tz-offset | ||
| (let* ((d1 (make-date 123456789 45 30 14 25 12 2023 28800)) | ||
| (t (date->time-utc d1)) | ||
| (d2 (time-utc->date t (date-zone-offset d1)))) | ||
| (check (date-year d2) => (date-year d1)) | ||
| (check (date-month d2) => (date-month d1)) | ||
| (check (date-day d2) => (date-day d1)) | ||
| (check (date-hour d2) => (date-hour d1)) | ||
| (check (date-minute d2) => (date-minute d1)) | ||
| (check (date-second d2) => (date-second d1)) | ||
| (check (date-nanosecond d2) => (date-nanosecond d1)) | ||
| (check (date-zone-offset d2) => (date-zone-offset d1))) | ||
|
|
||
| ;; converter error conditions | ||
| (check-catch 'wrong-type-arg | ||
| (time-utc->date (make-time TIME-TAI 0 0) 0)) | ||
| (check-catch 'wrong-type-arg | ||
| (time-utc->date (make-time TIME-UTC 0 0) "bad-offset")) | ||
| (check-catch 'wrong-type-arg | ||
| (date->time-utc "not-a-date")) | ||
|
|
||
| ;; ==================== | ||
| ;; Date to String/String to Date Converters | ||
| ;; ==================== | ||
|
|
||
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.
可能是这个算错了