You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Embed timezone conversion into conversion-function framework
This is a new implementation of the timezone conversion functionality on
top of the conversion-function framework. Previously, we could convert
`DateTime`s using `dt -> "Europe/Berlin"`, i.e. with a string on the
right hand side. This required special handling in the type checker,
the compiler and the Vm.
With this change, we use conversion functions instead. This requires
users to type `dt -> tz("Europe/Berlin")`, but is conceptually cleaner
and does not require special handling in the compiler. Well it does
require special handling in the FFI module for now, but only because we
don't have anonymous functions / closures yet.
I think this is still a benefitial change overall, as it makes the
conversion operator conceptually simpler. It can either have a unit on
the right hand side, or a conversion function.
We also introduce a new `local = tz(get_local_timezone())` function
which is a bit simpler to type (`dt -> local`) compared to the special
"local" string before.
Like before, users can still set aliases for timezones. For example:
```
let Florida = tz("US/Eastern")
now() -> Florida
```
parse_datetime("2024-11-01 12:30:00 Australia/Sydney") -> local
23
23
24
24
# What is the current UNIX timestamp?
25
25
now() -> unixtime
@@ -40,7 +40,7 @@ The following operations are supported for `DateTime` objects:
40
40
|`DateTime`|`-`|`DateTime`| Duration between the two dates as a `Time`. In `seconds`, by default. Use normal conversion for other time units. |
41
41
|`DateTime`|`+`|`Time`| New `DateTime` by adding the duration to the date |
42
42
|`DateTime`|`-`|`Time`| New `DateTime` by subtracting the duration from the date |
43
-
|`DateTime`|`->`|`String`| Converts the datetime to the specified time zone. Note that you can use tab-completion for time zone names. |
43
+
|`DateTime`|`->`|`tz("…")`| Converts the datetime to the specified time zone. Note that you can use tab-completion for time zone names. |
44
44
45
45
<divclass="warning">
46
46
@@ -60,6 +60,9 @@ The following functions are available for date and time handling:
60
60
-`now() -> DateTime`: Returns the current date and time.
61
61
-`parse_datetime(input: String) -> DateTime`: Parses a string into a `DateTime` object.
62
62
-`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.
63
+
-`tz(tz: String) -> Fn[(DateTime) -> DateTime]`: Returns a timezone conversion function, typically used with the conversion operator (`datetime -> tz("Europe/Berlin")`)
64
+
-`local(dt: DateTime) -> DateTime`: Timezone conversion function targeting the users local timezone (`datetime -> local`)
65
+
-`get_local_timezone() -> String`: Returns the users local timezone
63
66
-`unixtime(dt: DateTime) -> Scalar`: Converts a `DateTime` to a UNIX timestamp.
64
67
-`from_unixtime(ut: Scalar) -> DateTime`: Converts a UNIX timestamp to a `DateTime` object.
65
68
-`human(duration: Time) -> String`: Converts a `Time` to a human-readable string in days, hours, minutes and seconds
0 commit comments