Packages

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.

Current section

8 Versions

Jump to

Compare versions

5 files changed
+152 additions
-4 deletions
  @@ -1,5 +1,5 @@
1 1 name = "timeago"
2 - version = "2.2.0"
2 + version = "2.3.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.
  @@ -1,6 +1,6 @@
1 1 {<<"name">>, <<"timeago">>}.
2 2 {<<"app">>, <<"timeago">>}.
3 - {<<"version">>, <<"2.2.0">>}.
3 + {<<"version">>, <<"2.3.0">>}.
4 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">>]}.
  @@ -1,5 +1,5 @@
1 1 {application, timeago, [
2 - {vsn, "2.2.0"},
2 + {vsn, "2.3.0"},
3 3 {applications, [gleam_stdlib,
4 4 gleam_time]},
5 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."},
  @@ -1,7 +1,7 @@
1 1 -module(timeago).
2 2 -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
3 3 -define(FILEPATH, "src/timeago.gleam").
4 - -export([with_now/2, with_locale/2, format/2, en_us/3, new/0, fr/3, pt_br/3]).
4 + -export([with_now/2, with_locale/2, format/2, en_us/3, new/0, fr/3, pt_br/3, de_de/3]).
5 5 -export_type([time_ago/0, tense/0]).
6 6
7 7 -if(?OTP_RELEASE >= 27).
  @@ -518,3 +518,116 @@ pt_br(Tense, Unit, Amount) ->
518 518 _pipe@13 = <<"daqui a %d anos"/utf8>>,
519 519 replace_percent_d_with_int(_pipe@13, A@13)
520 520 end.
521 +
522 + -file("src/timeago.gleam", 284).
523 + ?DOC(" Translations for German\n").
524 + -spec de_de(tense(), gleam@time@duration:unit(), integer()) -> binary().
525 + de_de(Tense, Unit, Amount) ->
526 + case {Tense, Unit, Amount} of
527 + {_, nanosecond, _} ->
528 + <<"jetzt"/utf8>>;
529 +
530 + {_, microsecond, _} ->
531 + <<"jetzt"/utf8>>;
532 +
533 + {_, millisecond, _} ->
534 + <<"jetzt"/utf8>>;
535 +
536 + {past, second, 1} ->
537 + <<"vor einer Sekunde"/utf8>>;
538 +
539 + {past, second, A} ->
540 + _pipe = <<"vor %d Sekunden"/utf8>>,
541 + replace_percent_d_with_int(_pipe, A);
542 +
543 + {past, minute, 1} ->
544 + <<"vor einer Minute"/utf8>>;
545 +
546 + {past, minute, A@1} ->
547 + _pipe@1 = <<"vor %d Minuten"/utf8>>,
548 + replace_percent_d_with_int(_pipe@1, A@1);
549 +
550 + {past, hour, 1} ->
551 + <<"vor einer Stunde"/utf8>>;
552 +
553 + {past, hour, A@2} ->
554 + _pipe@2 = <<"vor %d Stunden"/utf8>>,
555 + replace_percent_d_with_int(_pipe@2, A@2);
556 +
557 + {past, day, 1} ->
558 + <<"vor einem Tag"/utf8>>;
559 +
560 + {past, day, A@3} ->
561 + _pipe@3 = <<"vor %d Tagen"/utf8>>,
562 + replace_percent_d_with_int(_pipe@3, A@3);
563 +
564 + {past, week, 1} ->
565 + <<"vor einer Woche"/utf8>>;
566 +
567 + {past, week, A@4} ->
568 + _pipe@4 = <<"vor %d Wochen"/utf8>>,
569 + replace_percent_d_with_int(_pipe@4, A@4);
570 +
571 + {past, month, 1} ->
572 + <<"vor einem Monat"/utf8>>;
573 +
574 + {past, month, A@5} ->
575 + _pipe@5 = <<"vor %d Monaten"/utf8>>,
576 + replace_percent_d_with_int(_pipe@5, A@5);
577 +
578 + {past, year, 1} ->
579 + <<"vor einem Jahr"/utf8>>;
580 +
581 + {past, year, A@6} ->
582 + _pipe@6 = <<"vor %d Jahren"/utf8>>,
583 + replace_percent_d_with_int(_pipe@6, A@6);
584 +
585 + {future, second, 1} ->
586 + <<"in einer Sekunde"/utf8>>;
587 +
588 + {future, second, A@7} ->
589 + _pipe@7 = <<"in %d Sekunden"/utf8>>,
590 + replace_percent_d_with_int(_pipe@7, A@7);
591 +
592 + {future, minute, 1} ->
593 + <<"in einer Minute"/utf8>>;
594 +
595 + {future, minute, A@8} ->
596 + _pipe@8 = <<"in %d Minuten"/utf8>>,
597 + replace_percent_d_with_int(_pipe@8, A@8);
598 +
599 + {future, hour, 1} ->
600 + <<"in einer Stunde"/utf8>>;
601 +
602 + {future, hour, A@9} ->
603 + _pipe@9 = <<"in %d Stunden"/utf8>>,
604 + replace_percent_d_with_int(_pipe@9, A@9);
605 +
606 + {future, day, 1} ->
607 + <<"in einem Tag"/utf8>>;
608 +
609 + {future, day, A@10} ->
610 + _pipe@10 = <<"in %d Tagen"/utf8>>,
611 + replace_percent_d_with_int(_pipe@10, A@10);
612 +
613 + {future, week, 1} ->
614 + <<"in einer Woche"/utf8>>;
615 +
616 + {future, week, A@11} ->
617 + _pipe@11 = <<"in %d Wochen"/utf8>>,
618 + replace_percent_d_with_int(_pipe@11, A@11);
619 +
620 + {future, month, 1} ->
621 + <<"in einem Monat"/utf8>>;
622 +
623 + {future, month, A@12} ->
624 + _pipe@12 = <<"in %d Monaten"/utf8>>,
625 + replace_percent_d_with_int(_pipe@12, A@12);
626 +
627 + {future, year, 1} ->
628 + <<"in einem Jahr"/utf8>>;
629 +
630 + {future, year, A@13} ->
631 + _pipe@13 = <<"in %d Jahren"/utf8>>,
632 + replace_percent_d_with_int(_pipe@13, A@13)
633 + end.
  @@ -279,3 +279,38 @@ pub fn pt_br(tense: Tense, unit: Unit, amount: Int) -> String {
279 279 Future, Year, a -> "daqui a %d anos" |> replace_percent_d_with_int(a)
280 280 }
281 281 }
282 +
283 + /// Translations for German
284 + pub fn de_de(tense: Tense, unit: Unit, amount: Int) -> String {
285 + case tense, unit, amount {
286 + _, Nanosecond, _ | _, Microsecond, _ | _, Millisecond, _ -> "jetzt"
287 + Past, Second, 1 -> "vor einer Sekunde"
288 + Past, Second, a -> "vor %d Sekunden" |> replace_percent_d_with_int(a)
289 + Past, Minute, 1 -> "vor einer Minute"
290 + Past, Minute, a -> "vor %d Minuten" |> replace_percent_d_with_int(a)
291 + Past, Hour, 1 -> "vor einer Stunde"
292 + Past, Hour, a -> "vor %d Stunden" |> replace_percent_d_with_int(a)
293 + Past, Day, 1 -> "vor einem Tag"
294 + Past, Day, a -> "vor %d Tagen" |> replace_percent_d_with_int(a)
295 + Past, Week, 1 -> "vor einer Woche"
296 + Past, Week, a -> "vor %d Wochen" |> replace_percent_d_with_int(a)
297 + Past, Month, 1 -> "vor einem Monat"
298 + Past, Month, a -> "vor %d Monaten" |> replace_percent_d_with_int(a)
299 + Past, Year, 1 -> "vor einem Jahr"
300 + Past, Year, a -> "vor %d Jahren" |> replace_percent_d_with_int(a)
301 + Future, Second, 1 -> "in einer Sekunde"
302 + Future, Second, a -> "in %d Sekunden" |> replace_percent_d_with_int(a)
303 + Future, Minute, 1 -> "in einer Minute"
304 + Future, Minute, a -> "in %d Minuten" |> replace_percent_d_with_int(a)
305 + Future, Hour, 1 -> "in einer Stunde"
306 + Future, Hour, a -> "in %d Stunden" |> replace_percent_d_with_int(a)
307 + Future, Day, 1 -> "in einem Tag"
308 + Future, Day, a -> "in %d Tagen" |> replace_percent_d_with_int(a)
309 + Future, Week, 1 -> "in einer Woche"
310 + Future, Week, a -> "in %d Wochen" |> replace_percent_d_with_int(a)
311 + Future, Month, 1 -> "in einem Monat"
312 + Future, Month, a -> "in %d Monaten" |> replace_percent_d_with_int(a)
313 + Future, Year, 1 -> "in einem Jahr"
314 + Future, Year, a -> "in %d Jahren" |> replace_percent_d_with_int(a)
315 + }
316 + }