Current section
8 Versions
Jump to
Current section
8 Versions
Compare versions
4
files changed
+16
additions
-16
deletions
| @@ -3,7 +3,7 @@ | |
| 3 3 | [](https://hex.pm/packages/timeago) |
| 4 4 | [](https://hexdocs.pm/timeago/) |
| 5 5 | |
| 6 | - A localized library for formatting timestamps as human-readable relative time strings. |
| 6 | + A lightweight Gleam library for formatting timestamps as human-readable relative time strings (e.g., '5 minutes ago', 'in 2 hours') with support for multiple locales. |
| 7 7 | |
| 8 8 | ## Installation |
| 9 9 | |
| @@ -22,7 +22,7 @@ import timeago | |
| 22 22 | |
| 23 23 | pub fn main() { |
| 24 24 | let past = timestamp.add(timestamp.system_time(), duration.minutes(-5)) |
| 25 | - |
| 25 | + |
| 26 26 | timeago.new() |
| 27 27 | |> timeago.format(past) |
| 28 28 | // -> "5 minutes ago" |
| @@ -38,7 +38,7 @@ import timeago | |
| 38 38 | pub fn main() { |
| 39 39 | let assert Ok(reference) = timestamp.parse_rfc3339("2024-01-01T12:00:00Z") |
| 40 40 | let assert Ok(past) = timestamp.parse_rfc3339("2024-01-01T11:00:00Z") |
| 41 | - |
| 41 | + |
| 42 42 | timeago.new() |
| 43 43 | |> timeago.with_now(reference) |
| 44 44 | |> timeago.format(past) |
| @@ -57,12 +57,12 @@ import timeago | |
| 57 57 | |
| 58 58 | pub fn main() { |
| 59 59 | let past = timestamp.add(timestamp.system_time(), duration.hours(-2)) |
| 60 | - |
| 60 | + |
| 61 61 | // English (US) - default |
| 62 62 | timeago.new() |
| 63 63 | |> timeago.format(past) |
| 64 64 | // -> "2 hours ago" |
| 65 | - |
| 65 | + |
| 66 66 | // French |
| 67 67 | timeago.new() |
| 68 68 | |> timeago.with_locale(timeago.fr) |
| @@ -83,18 +83,18 @@ import timeago | |
| 83 83 | pub fn main() { |
| 84 84 | let now = timestamp.system_time() |
| 85 85 | let formatter = timeago.new() |
| 86 | - |
| 86 | + |
| 87 87 | // Sub-second durations |
| 88 88 | formatter |> timeago.format(timestamp.add(now, duration.milliseconds(-500))) |
| 89 89 | // -> "just now" |
| 90 | - |
| 90 | + |
| 91 91 | // Seconds to years |
| 92 92 | formatter |> timeago.format(timestamp.add(now, duration.seconds(-45))) |
| 93 93 | // -> "45 seconds ago" |
| 94 | - |
| 94 | + |
| 95 95 | formatter |> timeago.format(timestamp.add(now, duration.days(-3))) |
| 96 96 | // -> "3 days ago" |
| 97 | - |
| 97 | + |
| 98 98 | formatter |> timeago.format(timestamp.add(now, duration.days(365))) |
| 99 99 | // -> "in 1 year" |
| 100 100 | } |
| @@ -107,4 +107,4 @@ Further documentation can be found at <https://hexdocs.pm/timeago>. | |
| 107 107 | ```sh |
| 108 108 | gleam run # Run the project |
| 109 109 | gleam test # Run the tests |
| 110 | - ``` |
| \ No newline at end of file | |
| 110 | + ``` |
| @@ -1,10 +1,10 @@ | |
| 1 1 | name = "timeago" |
| 2 | - version = "2.0.0" |
| 2 | + version = "2.1.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. |
| 6 6 | # |
| 7 | - description = "A lightweight library for describing time differences in a human readable format (e.g., '1 minute ago')." |
| 7 | + description = "A lightweight Gleam library for formatting timestamps as human-readable relative time strings (e.g., '5 minutes ago', 'in 2 hours') with support for multiple locales." |
| 8 8 | licences = ["Apache-2.0"] |
| 9 9 | repository = { type = "github", user = "ayoung19", repo = "timeago" } |
| 10 10 | # links = [{ title = "Website", href = "" }] |
| @@ -1,7 +1,7 @@ | |
| 1 1 | {<<"name">>, <<"timeago">>}. |
| 2 2 | {<<"app">>, <<"timeago">>}. |
| 3 | - {<<"version">>, <<"2.0.0">>}. |
| 4 | - {<<"description">>, <<"A lightweight library for describing time differences in a human readable format (e.g., '1 minute ago')."/utf8>>}. |
| 3 | + {<<"version">>, <<"2.1.0">>}. |
| 4 | + {<<"description">>, <<"A lightweight Gleam library for formatting timestamps as human-readable relative time strings (e.g., '5 minutes ago', 'in 2 hours') with support for multiple locales."/utf8>>}. |
| 5 5 | {<<"licenses">>, [<<"Apache-2.0">>]}. |
| 6 6 | {<<"build_tools">>, [<<"gleam">>]}. |
| 7 7 | {<<"links">>, [ |
| @@ -1,8 +1,8 @@ | |
| 1 1 | {application, timeago, [ |
| 2 | - {vsn, "2.0.0"}, |
| 2 | + {vsn, "2.1.0"}, |
| 3 3 | {applications, [gleam_stdlib, |
| 4 4 | gleam_time]}, |
| 5 | - {description, "A lightweight library for describing time differences in a human readable format (e.g., '1 minute ago')."}, |
| 5 | + {description, "A lightweight Gleam library for formatting timestamps as human-readable relative time strings (e.g., '5 minutes ago', 'in 2 hours') with support for multiple locales."}, |
| 6 6 | {modules, [timeago, |
| 7 7 | timeago@@main]}, |
| 8 8 | {registered, []} |