wobsite.time.parse_date
Show source codeHide source code
fn pub parse_date(string: String) -> Option[DateTime] {
let en = Locale.new
DateTime.parse(string, format: '%Y-%m-%dT%H:%M:%S', locale: en).else(fn {
DateTime.parse(string, format: '%Y-%m-%d', locale: en)
})
}
fn pub static parse_date(string: String) -> Option[DateTime]
Parses a DateTime
from a String
using the English locale.
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') # => Option.Some(DateTime(...))