From ecbab755737f53935fed3dd15da4f15bb249e227 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Tue, 28 Feb 2023 11:19:10 -0500 Subject: [PATCH 1/7] Append bash-specific instructions to gigasecond --- .../gigasecond/.docs/instructions.append.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 exercises/practice/gigasecond/.docs/instructions.append.md diff --git a/exercises/practice/gigasecond/.docs/instructions.append.md b/exercises/practice/gigasecond/.docs/instructions.append.md new file mode 100644 index 00000000..416516af --- /dev/null +++ b/exercises/practice/gigasecond/.docs/instructions.append.md @@ -0,0 +1,31 @@ +# placeholder + +## How to solve with bash + +`bash` does not have any builtin ways to **parse** datetime strings. +This exercise requires you to call out to some external utility. + +* The GNU `date` command's `-d` option can parse [a wide variety of formats][gnu-date]. +* If you're on a Mac, the [BSD `date` command][bsd-date] and its `-f` option. +* Perl is widely available, and it's [`Time::Piece` module][time-piece] is suitable. + +bash can **format** dates though. +Given an integer time value (an epoch time value), [the `printf` `%()T` formatter][bash-printf] can be given a "strftime"-style format string. +An example: + +```bash +epoch=1234567890 + +printf '%(%Y-%m-%d %H:%M:%S)T\n' "$epoch" +# ==> 2009-02-13 18:31:30 + +# Even in different timezones + +TZ=Asia/Kolkata printf '%(%Y-%m-%d %H:%M:%S)T\n' "$epoch" +# ==> 2009-02-14 05:01:30 +``` + +[gnu-date]: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html#Date-input-formats +[bsd-date]: https://manpage.me/index.cgi?apropos=0&q=date&sektion=0&manpath=FreeBSD+12-CURRENT+and+Ports&arch=default&format=html +[time-piece]: https://perldoc.pl/Time::Piece +[bash-printf]: https://www.gnu.org/software/bash/manual/bash.html#index-printf From 9591ccccb6db653c8b022fb10f0d8635511c3841 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Tue, 28 Feb 2023 21:42:11 -0500 Subject: [PATCH 2/7] Update exercises/practice/gigasecond/.docs/instructions.append.md Co-authored-by: Isaac Good --- exercises/practice/gigasecond/.docs/instructions.append.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/gigasecond/.docs/instructions.append.md b/exercises/practice/gigasecond/.docs/instructions.append.md index 416516af..f5649a0a 100644 --- a/exercises/practice/gigasecond/.docs/instructions.append.md +++ b/exercises/practice/gigasecond/.docs/instructions.append.md @@ -3,7 +3,7 @@ ## How to solve with bash `bash` does not have any builtin ways to **parse** datetime strings. -This exercise requires you to call out to some external utility. +This exercise requires you to call out to an external utility. * The GNU `date` command's `-d` option can parse [a wide variety of formats][gnu-date]. * If you're on a Mac, the [BSD `date` command][bsd-date] and its `-f` option. From 6278d99ead730dc66869782db330fa850624ecb1 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Tue, 28 Feb 2023 21:42:24 -0500 Subject: [PATCH 3/7] Update exercises/practice/gigasecond/.docs/instructions.append.md Co-authored-by: Isaac Good --- exercises/practice/gigasecond/.docs/instructions.append.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/gigasecond/.docs/instructions.append.md b/exercises/practice/gigasecond/.docs/instructions.append.md index f5649a0a..51bc40a7 100644 --- a/exercises/practice/gigasecond/.docs/instructions.append.md +++ b/exercises/practice/gigasecond/.docs/instructions.append.md @@ -6,7 +6,7 @@ This exercise requires you to call out to an external utility. * The GNU `date` command's `-d` option can parse [a wide variety of formats][gnu-date]. -* If you're on a Mac, the [BSD `date` command][bsd-date] and its `-f` option. +* For Mac users, see the [BSD `date` command][bsd-date] and its `-f` option. * Perl is widely available, and it's [`Time::Piece` module][time-piece] is suitable. bash can **format** dates though. From 785e2716160e3c5eb74612100ff4bb5945031341 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Tue, 28 Feb 2023 21:42:36 -0500 Subject: [PATCH 4/7] Update exercises/practice/gigasecond/.docs/instructions.append.md Co-authored-by: Isaac Good --- exercises/practice/gigasecond/.docs/instructions.append.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/gigasecond/.docs/instructions.append.md b/exercises/practice/gigasecond/.docs/instructions.append.md index 51bc40a7..698a7852 100644 --- a/exercises/practice/gigasecond/.docs/instructions.append.md +++ b/exercises/practice/gigasecond/.docs/instructions.append.md @@ -7,7 +7,7 @@ This exercise requires you to call out to an external utility. * The GNU `date` command's `-d` option can parse [a wide variety of formats][gnu-date]. * For Mac users, see the [BSD `date` command][bsd-date] and its `-f` option. -* Perl is widely available, and it's [`Time::Piece` module][time-piece] is suitable. +* Perl is widely available, and its [`Time::Piece` module][time-piece] is can be used to parse timestamps. bash can **format** dates though. Given an integer time value (an epoch time value), [the `printf` `%()T` formatter][bash-printf] can be given a "strftime"-style format string. From dfa7c9cb5dcd177ba62032373bdf44fc12d2f036 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Tue, 28 Feb 2023 21:43:05 -0500 Subject: [PATCH 5/7] Update exercises/practice/gigasecond/.docs/instructions.append.md Co-authored-by: Isaac Good --- exercises/practice/gigasecond/.docs/instructions.append.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/exercises/practice/gigasecond/.docs/instructions.append.md b/exercises/practice/gigasecond/.docs/instructions.append.md index 698a7852..cef70b56 100644 --- a/exercises/practice/gigasecond/.docs/instructions.append.md +++ b/exercises/practice/gigasecond/.docs/instructions.append.md @@ -9,9 +9,8 @@ This exercise requires you to call out to an external utility. * For Mac users, see the [BSD `date` command][bsd-date] and its `-f` option. * Perl is widely available, and its [`Time::Piece` module][time-piece] is can be used to parse timestamps. -bash can **format** dates though. -Given an integer time value (an epoch time value), [the `printf` `%()T` formatter][bash-printf] can be given a "strftime"-style format string. -An example: +bash can **format** dates without any external tools. +Given an integer time value (seconds since the epoch), [the `printf` `%()T` formatter][bash-printf] can apply "strftime"-style formatting. ```bash epoch=1234567890 From fa0c31620ce5d6731222fa30828ddf99dbea4329 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Tue, 28 Feb 2023 21:43:16 -0500 Subject: [PATCH 6/7] Update exercises/practice/gigasecond/.docs/instructions.append.md Co-authored-by: Isaac Good --- exercises/practice/gigasecond/.docs/instructions.append.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/gigasecond/.docs/instructions.append.md b/exercises/practice/gigasecond/.docs/instructions.append.md index cef70b56..5111bfc0 100644 --- a/exercises/practice/gigasecond/.docs/instructions.append.md +++ b/exercises/practice/gigasecond/.docs/instructions.append.md @@ -18,7 +18,7 @@ epoch=1234567890 printf '%(%Y-%m-%d %H:%M:%S)T\n' "$epoch" # ==> 2009-02-13 18:31:30 -# Even in different timezones +# bash uses the `TZ` environment variable for the timezone. TZ=Asia/Kolkata printf '%(%Y-%m-%d %H:%M:%S)T\n' "$epoch" # ==> 2009-02-14 05:01:30 From 668bd17abe932fa1537c3f82346649b552090c1d Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Wed, 1 Mar 2023 08:12:21 -0500 Subject: [PATCH 7/7] Update exercises/practice/gigasecond/.docs/instructions.append.md Co-authored-by: Isaac Good --- exercises/practice/gigasecond/.docs/instructions.append.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/gigasecond/.docs/instructions.append.md b/exercises/practice/gigasecond/.docs/instructions.append.md index 5111bfc0..d06cdc5d 100644 --- a/exercises/practice/gigasecond/.docs/instructions.append.md +++ b/exercises/practice/gigasecond/.docs/instructions.append.md @@ -7,7 +7,7 @@ This exercise requires you to call out to an external utility. * The GNU `date` command's `-d` option can parse [a wide variety of formats][gnu-date]. * For Mac users, see the [BSD `date` command][bsd-date] and its `-f` option. -* Perl is widely available, and its [`Time::Piece` module][time-piece] is can be used to parse timestamps. +* Perl is widely available, and its [`Time::Piece` module][time-piece] can be used to parse timestamps. bash can **format** dates without any external tools. Given an integer time value (seconds since the epoch), [the `printf` `%()T` formatter][bash-printf] can apply "strftime"-style formatting.