Skip to content
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

time: add documentation for time-related functions and ISO 8601 parsing #23867

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions vlib/time/parse.js.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub fn parse(s string) Time {
return res
}

// parse_iso8601 parses the ISO 8601 time format yyyy-MM-ddTHH:mm:ss.dddddd+dd:dd as local time.
// The fraction part is difference in milli seconds, and the last part is offset from UTC time.
// Both can be +/- HH:mm .
// See https://en.wikipedia.org/wiki/ISO_8601 .
// Remarks: not all of ISO 8601 is supported; checks and support for leapseconds should be added.
pub fn parse_iso8601(s string) !Time {
return parse(s)
}
4 changes: 4 additions & 0 deletions vlib/time/time.js.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module time

// now returns the current local time.
pub fn now() Time {
mut res := Time{}
#let date = new Date()
Expand All @@ -15,6 +16,7 @@ pub fn now() Time {
return res
}

// utc returns the current UTC time.
pub fn utc() Time {
mut res := Time{}
#let date = new Date()
Expand Down Expand Up @@ -61,6 +63,8 @@ fn time_with_unix(t Time) Time {
return res
}

// ticks returns the number of milliseconds since the UNIX epoch.
// // On Windows ticks returns the number of milliseconds elapsed since system start.
pub fn ticks() i64 {
t := i64(0)
#t.val = BigInt(new Date().getTime())
Expand Down
1 change: 1 addition & 0 deletions vlib/time/time.v
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub enum FormatDelimiter {
no_delimiter
}

// new returns a time struct with the calculated Unix time.
pub fn Time.new(t Time) Time {
return time_with_unix(t)
}
Expand Down
Loading