hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 87bd84448a2d544bee271afc07f20a50209c2370
parent fda0df4aa66397061e4e9f3fde8537426b20800a
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun, 16 Jan 2022 19:24:45 +0000

new datetime::from_str()

Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mdatetime/datetime.ha | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/datetime/datetime.ha b/datetime/datetime.ha @@ -111,6 +111,16 @@ export fn from_moment(m: chrono::moment) datetime = { return dt; }; +// Creates a [[datetime]] from a string, parsed according to a layout, +// using [[method::ALL]], or fails otherwise. +// +// TODO: allow the user to specify methods for security? +export fn from_str(layout: str, s: str) (datetime | insufficient | errors::invalid) = { + const b = newbuilder(); + parse(&b, layout, s)?; + return build(&b)?; +}; + // Creates a [[chrono::moment]] from a [[datetime]] export fn to_moment(dt: datetime) chrono::moment = { return chrono::moment {