Current section
3 Versions
Jump to
Current section
3 Versions
Compare versions
6
files changed
+63
additions
-23
deletions
| @@ -11,7 +11,7 @@ gleam add gtempo@5 | |
| 11 11 | |
| 12 12 | This package was written to be used with the [Tempo](https://hexdocs.pm/gtempo/index.html) package, but could be expanded to provide timezone support for other libraries as well! Contributions are welcome! Currently this package is very simple and only supports converting non-naive datetimes to a specific timezone via Tempo; it does not support constructing new datetimes in a specific timezone or assigning a timezone to an existing naive datetime. |
| 13 13 | |
| 14 | - Ambiguous datetimes and DST boundries are not handled explicitly by this package, but instead rely on the target timezone package's default handling. It seems like the Elixir package prefers the future time and JavaScript prefers the past time for DST boundries. Once ambiguous datetimes are worked out to be a little more explicit or obvious in this package, there will probably be a v1 release. |
| 14 | + Ambiguous datetimes and DST boundaries are not handled explicitly by this package, but instead rely on the target timezone package's default handling. It seems like the Elixir package prefers the future time and JavaScript prefers the past time for DST boundaries. Once ambiguous datetimes are worked out to be a little more explicit or obvious in this package, there will probably be a v1 release. |
| 15 15 | |
| 16 16 | Supports both the Erlang and JavaScript targets. |
| @@ -1,5 +1,5 @@ | |
| 1 1 | name = "gtz" |
| 2 | - version = "0.1.0" |
| 2 | + version = "0.2.0" |
| 3 3 | |
| 4 4 | # Fill out these fields if you intend to generate HTML documentation or publish |
| 5 5 | # your project to the Hex package manager. |
| @@ -16,7 +16,7 @@ links = [{ title = "Website", href = "https://gleam.run" }] | |
| 16 16 | gleam_stdlib = ">= 0.34.0 and < 2.0.0" |
| 17 17 | tz = ">= 0.28.1 and < 1.0.0" |
| 18 18 | timex = ">= 3.7.11 and < 4.0.0" |
| 19 | - gtempo = ">= 5.0.0" |
| 19 | + gtempo = ">= 7.0.0 and < 8.0.0" |
| 20 20 | |
| 21 21 | [dev-dependencies] |
| 22 22 | gleeunit = ">= 1.0.0 and < 2.0.0" |
| @@ -1,6 +1,6 @@ | |
| 1 1 | {<<"name">>, <<"gtz">>}. |
| 2 2 | {<<"app">>, <<"gtz">>}. |
| 3 | - {<<"version">>, <<"0.1.0">>}. |
| 3 | + {<<"version">>, <<"0.2.0">>}. |
| 4 4 | {<<"description">>, <<"A timezone data provider for Gleam! "/utf8>>}. |
| 5 5 | {<<"licenses">>, [<<"Apache-2.0">>]}. |
| 6 6 | {<<"build_tools">>, [<<"gleam">>]}. |
| @@ -9,25 +9,25 @@ | |
| 9 9 | {<<"Repository">>, <<"https://github.com/jrstrunk/gtz">>} |
| 10 10 | ]}. |
| 11 11 | {<<"requirements">>, [ |
| 12 | - {<<"gtempo">>, [ |
| 13 | - {<<"app">>, <<"gtempo">>}, |
| 12 | + {<<"gleam_stdlib">>, [ |
| 13 | + {<<"app">>, <<"gleam_stdlib">>}, |
| 14 14 | {<<"optional">>, false}, |
| 15 | - {<<"requirement">>, <<">= 5.0.0">>} |
| 16 | - ]}, |
| 17 | - {<<"tz">>, [ |
| 18 | - {<<"app">>, <<"tz">>}, |
| 19 | - {<<"optional">>, false}, |
| 20 | - {<<"requirement">>, <<">= 0.28.1 and < 1.0.0">>} |
| 15 | + {<<"requirement">>, <<">= 0.34.0 and < 2.0.0">>} |
| 21 16 | ]}, |
| 22 17 | {<<"timex">>, [ |
| 23 18 | {<<"app">>, <<"timex">>}, |
| 24 19 | {<<"optional">>, false}, |
| 25 20 | {<<"requirement">>, <<">= 3.7.11 and < 4.0.0">>} |
| 26 21 | ]}, |
| 27 | - {<<"gleam_stdlib">>, [ |
| 28 | - {<<"app">>, <<"gleam_stdlib">>}, |
| 22 | + {<<"gtempo">>, [ |
| 23 | + {<<"app">>, <<"gtempo">>}, |
| 29 24 | {<<"optional">>, false}, |
| 30 | - {<<"requirement">>, <<">= 0.34.0 and < 2.0.0">>} |
| 25 | + {<<"requirement">>, <<">= 7.0.0 and < 8.0.0">>} |
| 26 | + ]}, |
| 27 | + {<<"tz">>, [ |
| 28 | + {<<"app">>, <<"tz">>}, |
| 29 | + {<<"optional">>, false}, |
| 30 | + {<<"requirement">>, <<">= 0.28.1 and < 1.0.0">>} |
| 31 31 | ]} |
| 32 32 | ]}. |
| 33 33 | {<<"files">>, [ |
| @@ -1,11 +1,12 @@ | |
| 1 1 | {application, gtz, [ |
| 2 | - {vsn, "0.1.0"}, |
| 2 | + {vsn, "0.2.0"}, |
| 3 3 | {applications, [gleam_stdlib, |
| 4 | - gleeunit, |
| 5 4 | gtempo, |
| 6 5 | timex, |
| 7 6 | tz]}, |
| 8 7 | {description, "A timezone data provider for Gleam! "}, |
| 9 | - {modules, [gtz]}, |
| 8 | + {modules, ['Elixir.GTZ_FFI', |
| 9 | + gtz, |
| 10 | + gtz@@main]}, |
| 10 11 | {registered, []} |
| 11 12 | ]}. |
| @@ -3,7 +3,33 @@ | |
| 3 3 | |
| 4 4 | -export([timezone/1, local_name/0]). |
| 5 5 | |
| 6 | - -file("/home/john/Repos/gtz/src/gtz.gleam", 21). |
| 6 | + -if(?OTP_RELEASE >= 27). |
| 7 | + -define(MODULEDOC(Str), -moduledoc(Str)). |
| 8 | + -define(DOC(Str), -doc(Str)). |
| 9 | + -else. |
| 10 | + -define(MODULEDOC(Str), -compile([])). |
| 11 | + -define(DOC(Str), -compile([])). |
| 12 | + -endif. |
| 13 | + |
| 14 | + ?MODULEDOC(" Functions to provide simple timezone support for other Gleam datetime libraries.\n"). |
| 15 | + |
| 16 | + -file("src/gtz.gleam", 22). |
| 17 | + ?DOC( |
| 18 | + " Constructs a TimeZoneProvider type to be used with the Tempo package. \n" |
| 19 | + " Returns an error if the timezone is not valid.\n" |
| 20 | + " \n" |
| 21 | + " ## Examples\n" |
| 22 | + " \n" |
| 23 | + " ```gleam\n" |
| 24 | + " import tempo/datetime\n" |
| 25 | + "\n" |
| 26 | + " let assert Ok(tz) = gtz.timezone(\"America/New_York\")\n" |
| 27 | + " datetime.literal(\"2024-06-21T06:30:02.334Z\")\n" |
| 28 | + " |> datetime.to_timezone(tz)\n" |
| 29 | + " |> datetime.to_string\n" |
| 30 | + " // -> \"2024-01-03T02:30:02.334-04:00\"\n" |
| 31 | + " ```\n" |
| 32 | + ). |
| 7 33 | -spec timezone(binary()) -> {ok, tempo:time_zone_provider()} | {error, nil}. |
| 8 34 | timezone(Name) -> |
| 9 35 | case 'Elixir.GTZ_FFI':is_valid_timezone(Name) of |
| @@ -25,7 +51,8 @@ timezone(Name) -> | |
| 25 51 | Second, |
| 26 52 | Name |
| 27 53 | ), |
| 28 | - tempo@offset:new(_pipe) |
| 54 | + _pipe@1 = tempo@duration:minutes(_pipe), |
| 55 | + tempo@offset:from_duration(_pipe@1) |
| 29 56 | end, |
| 30 57 | {ok, Offset} = case _assert_subject of |
| 31 58 | {ok, _} -> _assert_subject; |
| @@ -35,7 +62,7 @@ timezone(Name) -> | |
| 35 62 | value => _assert_fail, |
| 36 63 | module => <<"gtz"/utf8>>, |
| 37 64 | function => <<"timezone"/utf8>>, |
| 38 | - line => 31}) |
| 65 | + line => 32}) |
| 39 66 | end, |
| 40 67 | Offset |
| 41 68 | end}}; |
| @@ -44,7 +71,17 @@ timezone(Name) -> | |
| 44 71 | {error, nil} |
| 45 72 | end. |
| 46 73 | |
| 47 | - -file("/home/john/Repos/gtz/src/gtz.gleam", 69). |
| 74 | + -file("src/gtz.gleam", 71). |
| 75 | + ?DOC( |
| 76 | + " Returns the name of the host system's timezone.\n" |
| 77 | + " \n" |
| 78 | + " ## Examples\n" |
| 79 | + " \n" |
| 80 | + " ```gleam\n" |
| 81 | + " gtz.local_name()\n" |
| 82 | + " // -> \"Europe/London\"\n" |
| 83 | + " ```\n" |
| 84 | + ). |
| 48 85 | -spec local_name() -> binary(). |
| 49 86 | local_name() -> |
| 50 87 | 'Elixir.Timex.Timezone.Local':lookup(). |
Loading more files…