From 81776f724a4939fb70ce4774a9a1d0b352ab622f Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Thu, 31 Oct 2024 00:25:14 +0800 Subject: [PATCH] Add date/time conversion related scripts --- .config/scripts/bin/timestamp-discord | 1 + .config/scripts/bin/timezones | 1 + .config/scripts/bin/timezones-from | 1 + .config/scripts/date/timestamp-discord | 12 +++++++++++ .config/scripts/date/timezones | 29 ++++++++++++++++++++++++++ .config/scripts/date/timezones-from | 13 ++++++++++++ 6 files changed, 57 insertions(+) create mode 120000 .config/scripts/bin/timestamp-discord create mode 120000 .config/scripts/bin/timezones create mode 120000 .config/scripts/bin/timezones-from create mode 100755 .config/scripts/date/timestamp-discord create mode 100755 .config/scripts/date/timezones create mode 100755 .config/scripts/date/timezones-from diff --git a/.config/scripts/bin/timestamp-discord b/.config/scripts/bin/timestamp-discord new file mode 120000 index 0000000..9c4e043 --- /dev/null +++ b/.config/scripts/bin/timestamp-discord @@ -0,0 +1 @@ +../date/timestamp-discord \ No newline at end of file diff --git a/.config/scripts/bin/timezones b/.config/scripts/bin/timezones new file mode 120000 index 0000000..577be60 --- /dev/null +++ b/.config/scripts/bin/timezones @@ -0,0 +1 @@ +../date/timezones \ No newline at end of file diff --git a/.config/scripts/bin/timezones-from b/.config/scripts/bin/timezones-from new file mode 120000 index 0000000..db8393f --- /dev/null +++ b/.config/scripts/bin/timezones-from @@ -0,0 +1 @@ +../date/timezones-from \ No newline at end of file diff --git a/.config/scripts/date/timestamp-discord b/.config/scripts/date/timestamp-discord new file mode 100755 index 0000000..c90e068 --- /dev/null +++ b/.config/scripts/date/timestamp-discord @@ -0,0 +1,12 @@ +#!/bin/bash +time="$1" +if [ -z "$1" ]; then + time="now" +fi + +unix="$(date -d "$time" +%s)" +wl-copy " " + +echo "The discord timestamp for:" +date -d "@${unix}" +echo "is copied to the clipboard" diff --git a/.config/scripts/date/timezones b/.config/scripts/date/timezones new file mode 100755 index 0000000..32bd1db --- /dev/null +++ b/.config/scripts/date/timezones @@ -0,0 +1,29 @@ +#!/bin/bash +# +# List of time zones to iterate through +timezones=( + "UTC" + "America/Los_Angeles" + #"Europe/London" + "Europe/Stockholm" +) +sep="------------------------------------------------" + +time="$1" +if [ -z "$1" ]; then + time="now" +fi + +echo $sep +echo "My Time:" +TZ="$(cat /etc/timezone)" date -d "@$(date -d "$time" +%s)" +echo $sep + +# Loop through each time zone and calculate the new time +for tz in "${timezones[@]}" +do + echo "Timezone: $tz" + TZ="$tz" date -d "@$(date -d "$time" +%s)" + echo $sep +done + diff --git a/.config/scripts/date/timezones-from b/.config/scripts/date/timezones-from new file mode 100755 index 0000000..af21f77 --- /dev/null +++ b/.config/scripts/date/timezones-from @@ -0,0 +1,13 @@ +#!/bin/bash +time="$1" +if [ -z "$1" ]; then + time="now" +fi + +pushd . > /dev/null +cd /usr/share/zoneinfo/ +tz="$(find | sed 's|^\./||' | fzf)" +popd > /dev/null + +unix="$(TZ="$tz" date -d "$time" +%s)" +date -d "@${unix}"