wobsite.time.parse_date
Show source codeHide source code
fn pub parse_date(string: String) -> Option[DateTime] {
if string.size < 10 { return Option.None }
Option.Some(
DateTime(
year: try parse_number(string, start: 0, size: 4),
month: try parse_number(string, start: 5, size: 2),
day: try parse_number(string, start: 8, size: 2),
hour: parse_number(string, start: 11, size: 2).or(0),
minute: parse_number(string, start: 14, size: 2).or(0),
second: parse_number(string, start: 17, size: 2).or(0),
sub_second: 0.0,
utc_offset: 0,
),
)
}
fn pub static parse_date(string: String) -> Option[DateTime]
Parses a DateTime
from a String
.
The expected format is YYYY-MM-DDTHH:MM:SS
. The year, month, and day are
required, but the rest is optional.
Errors
If the input is invalid, an Option.None
is returned.
Examples
import wobsite.time (parse_date)
parse_date('2024-01-02T13:14:15:Z') # => Option.Some(DateTime(year: 2024, month: 1, day: 2, hour: 13, minute: 14, second: 15, sub_second: 0.0, utc_offset: 0))