Browse Source

Rename parse_datetime => datetime

David Peter 1 year ago
parent
commit
f380f2c56a

+ 2 - 2
book/src/cli-installation.md

@@ -10,8 +10,8 @@ Download the latest `.deb` package from [the release page](https://github.com/sh
 and install it via `dpkg`. For example:
 
 ``` bash
-curl -LO https://github.com/sharkdp/numbat/releases/download/v1.9.0/numbat_1.9.0_amd64.deb
-sudo dpkg -i numbat_1.9.0_amd64.deb
+curl -LO https://github.com/sharkdp/numbat/releases/download/v1.10.0/numbat_1.10.0_amd64.deb
+sudo dpkg -i numbat_1.10.0_amd64.deb
 ```
 
 ### Arch Linux

+ 4 - 4
book/src/date-and-time.md

@@ -13,13 +13,13 @@ now() + 40 days
 now() - 1 million seconds
 
 # How many days are left until September 1st?
-parse_datetime("2024-11-01 12:30:00") - now() -> days
+datetime("2024-11-01 12:30:00") - now() -> days
 
 # What time is it in Nepal right now?
 now() -> tz("Asia/Kathmandu")  # use tab completion to find time zone names
 
 # What is the local time when it is 2024-11-01 12:30:00 in Australia?
-parse_datetime("2024-11-01 12:30:00 Australia/Sydney") -> local
+datetime("2024-11-01 12:30:00 Australia/Sydney") -> local
 
 # What is the current UNIX timestamp?
 now() -> unixtime
@@ -58,7 +58,7 @@ April 1st"?
 The following functions are available for date and time handling:
 
 - `now() -> DateTime`: Returns the current date and time.
-- `parse_datetime(input: String) -> DateTime`: Parses a string into a `DateTime` object.
+- `datetime(input: String) -> DateTime`: Parses a string into a `DateTime` object.
 - `format_datetime(format: String, dt: DateTime) -> String`: Formats a `DateTime` object as a string. See [this page](https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers) for possible format specifiers.
 - `tz(tz: String) -> Fn[(DateTime) -> DateTime]`: Returns a timezone conversion function, typically used with the conversion operator (`datetime -> tz("Europe/Berlin")`)
 - `local(dt: DateTime) -> DateTime`: Timezone conversion function targeting the users local timezone (`datetime -> local`)
@@ -69,7 +69,7 @@ The following functions are available for date and time handling:
 
 ## Date time formats
 
-The following formats are supported by `parse_datetime`. UTC offsets are mandatory for the RFC 3339 and
+The following formats are supported by `datetime`. UTC offsets are mandatory for the RFC 3339 and
 RFC 2822 formats. The other formats can optionally include a time zone name or UTC offset. If no time
 zone is specified, the local time zone is used.
 

+ 1 - 1
book/src/list-functions.md

@@ -103,7 +103,7 @@ fn sphere_volume<L>(radius: L) -> L^3
 
 ```nbt
 fn now() -> DateTime
-fn parse_datetime(input: String) -> DateTime
+fn datetime(input: String) -> DateTime
 fn format_datetime(format: String, dt: DateTime) -> String
 fn tz(tz: String) -> Fn[(DateTime) -> DateTime]
 fn local(dt: DateTime) -> DateTime

+ 4 - 4
examples/datetime_tests.nbt

@@ -1,15 +1,15 @@
-let epoch = parse_datetime("1970-01-01T00:00:00Z")
+let epoch = datetime("1970-01-01T00:00:00Z")
 assert_eq(epoch -> unixtime, 0)
 
 assert_eq(epoch + 1000 milliseconds + 2 seconds -> unixtime, 3)
 
-let x = parse_datetime("Wed, 20 Jul 2022 21:52:05 +0200")
+let x = datetime("Wed, 20 Jul 2022 21:52:05 +0200")
 assert_eq(x -> unixtime, 1658346725)
 
 assert_eq(from_unixtime(1658346725) -> unixtime, 1658346725)
 
 # 2020 was a leap year
-let y = parse_datetime("2020-02-28T20:00:00Z")
+let y = datetime("2020-02-28 20:00 UTC")
 assert(format_datetime("%Y/%m/%d", y + 12 hours) == "2020/02/29")
-let z = parse_datetime("2021-02-28T20:00:00Z")
+let z = datetime("2021-02-28 20:00 UTC")
 assert(format_datetime("%Y/%m/%d", z + 12 hours) == "2021/03/01")

+ 1 - 1
numbat/modules/datetime/functions.nbt

@@ -1,7 +1,7 @@
 use units::si
 
 fn now() -> DateTime
-fn parse_datetime(input: String) -> DateTime
+fn datetime(input: String) -> DateTime
 fn format_datetime(format: String, input: DateTime) -> String
 fn get_local_timezone() -> String
 fn tz(tz: String) -> Fn[(DateTime) -> DateTime]

+ 1 - 1
numbat/modules/datetime/human.nbt

@@ -33,4 +33,4 @@ fn _human_readable_duration(time: Time, dt: DateTime, num_days: Scalar) -> Strin
 fn human(time: Time) =
   if _human_num_days(time) > 1000
     then "{_human_num_days(time)} days" 
-    else _human_readable_duration(time, parse_datetime("0001-01-01T00:00:00Z") + time, _human_num_days(time))
+    else _human_readable_duration(time, datetime("0001-01-01T00:00:00Z") + time, _human_num_days(time))

+ 4 - 4
numbat/src/ffi.rs

@@ -358,11 +358,11 @@ pub(crate) fn functions() -> &'static HashMap<String, ForeignFunction> {
             },
         );
         m.insert(
-            "parse_datetime".to_string(),
+            "datetime".to_string(),
             ForeignFunction {
-                name: "parse_datetime".into(),
+                name: "datetime".into(),
                 arity: 1..=1,
-                callable: Callable::Function(Box::new(parse_datetime)),
+                callable: Callable::Function(Box::new(datetime)),
             },
         );
 
@@ -841,7 +841,7 @@ fn now(args: &[Value]) -> Result<Value> {
     Ok(Value::DateTime(now, offset))
 }
 
-fn parse_datetime(args: &[Value]) -> Result<Value> {
+fn datetime(args: &[Value]) -> Result<Value> {
     assert!(args.len() == 1);
 
     let input = args[0].unsafe_as_string();