From 0927d2ba8b31da125dba0d57841bccc5cc1204c4 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 13 May 2024 00:40:03 +0400 Subject: [PATCH] port `examples/date_in_local_timezones.nu` - embed the `core-team` table, remove `assets/core_team.nu` - embed the `date local` function from `language/std/date` - explicit print - `str collect` -> `str join` - `$block` -> `$closure` - `date format` -> `format date` --- before_v0.60/assets/core_team.nu | 12 ------ modules/examples/date_in_local_timezones.nu | 47 ++++++++++++++------- 2 files changed, 32 insertions(+), 27 deletions(-) delete mode 100644 before_v0.60/assets/core_team.nu diff --git a/before_v0.60/assets/core_team.nu b/before_v0.60/assets/core_team.nu deleted file mode 100644 index ed623d9b6..000000000 --- a/before_v0.60/assets/core_team.nu +++ /dev/null @@ -1,12 +0,0 @@ -def "nu core-team" [] { - [ - [ 'name', 'tz']; - [ 'andres', 'America/Guayaquil'] - [ 'fdncred', 'US/Central'] - [ 'gedge', 'US/Eastern'] - [ 'jt', 'NZ'] - [ 'wycats', 'US/Pacific'] - [ 'kubouch', 'Europe/Helsinki'] - ['elferherrera', 'Europe/London'] - ] -} diff --git a/modules/examples/date_in_local_timezones.nu b/modules/examples/date_in_local_timezones.nu index 2b8eb2c59..40518e299 100644 --- a/modules/examples/date_in_local_timezones.nu +++ b/modules/examples/date_in_local_timezones.nu @@ -1,25 +1,42 @@ -source lib/scripts.nu -source assets/core_team.nu -let next_call = ("2021-08-31 15:00:21.290597200 -05:00" | str to-datetime); +def "nu core-team" [] { + [ + [ 'name', 'tz']; + [ 'andres', 'America/Guayaquil'] + [ 'fdncred', 'US/Central'] + [ 'gedge', 'US/Eastern'] + [ 'jt', 'NZ'] + [ 'wycats', 'US/Pacific'] + [ 'kubouch', 'Europe/Helsinki'] + ['elferherrera', 'Europe/London'] + ] +} + +def "date local" [now] { + insert time {|value| + let converted = ($now | date to-timezone $value.tz); + + $converted | format date '%c' + } +} + +let next_call = ("2021-08-31 15:00:21.290597200 -05:00" | into datetime); let people = (nu core-team | date local $next_call); -def say [block] { - each {|person| - do $block ( - $person | merge { - [[name]; [($person.name | str capitalize)]] - } +def say [closure] { + $in | each {|person| + do $closure ( + $person | update name {|row| $row.name | str capitalize} ) - } | str collect (char newline) + } | str join (char newline) } -$people | say {|person| $"($person.name)'s timezone is ($person.tz)"} +print ($people | say {|person| $"($person.name)'s timezone is ($person.tz)"}) -$" +print ($" -for the next call happening on ($next_call | date format '%c').. in their timezones they would be: +for the next call happening on ($next_call | format date '%c').. in their timezones they would be: -" +") -$people | say {|person| $"($person.name)'s: ($person.time)"} +print ($people | say {|person| $"($person.name)'s: ($person.time)"})