aboutsummaryrefslogtreecommitdiff
path: root/quarter-timestamps
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-08-20 20:42:35 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-08-20 20:42:35 -0300
commit3c5c672e47737e6b3342dfeb730ccd8320f2d442 (patch)
treed08d27539f244e640cf1e92ed0f259929fdf5d32 /quarter-timestamps
downloadutils-organization-3c5c672e47737e6b3342dfeb730ccd8320f2d442.tar.gz
utils-organization-3c5c672e47737e6b3342dfeb730ccd8320f2d442.tar.bz2
Initial import
Diffstat (limited to 'quarter-timestamps')
-rwxr-xr-xquarter-timestamps50
1 files changed, 50 insertions, 0 deletions
diff --git a/quarter-timestamps b/quarter-timestamps
new file mode 100755
index 0000000..8f1bab5
--- /dev/null
+++ b/quarter-timestamps
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+#
+# Determine the quarter's timestamps
+#
+
+# Parameters
+BASENAME="`basename $0`"
+DIRNAME="`dirname $0`"
+QUARTER="$1"
+YEAR="`echo $QUARTER | cut -d . -f 1`"
+QUARTILE="`echo $QUARTER | cut -d . -f 2`"
+
+# Syntax check
+if [ -z "$QUARTILE" ]; then
+ echo "usage: $BASENAME <quarter>"
+ echo "quarter format: YYYY.QQ"
+ echo "example: 2024.Q3"
+ exit 1
+fi
+
+# Lookup table
+case $QUARTILE in
+ Q1)
+ BEGIN="01-01"
+ END="03-31"
+ ;;
+
+ Q2)
+ BEGIN="04-01"
+ END="06-30"
+ ;;
+
+ Q3)
+ BEGIN="07-01"
+ END="09-30"
+ ;;
+
+ Q4)
+ BEGIN="10-01"
+ END="12-31"
+ ;;
+esac
+
+# Determine the UNIX timestamp for the beginning and end of the quarter
+QUARTER_BEGIN="`date -d "${YEAR}-${BEGIN} 00:00:00 UTC" +%s`"
+QUARTER_END="`date -d "${YEAR}-${END} 00:00:00 UTC" +%s`"
+
+# Output
+echo "Quarter begins at UNIX timestamp $QUARTER_BEGIN ($YEAR-$BEGIN)"
+echo "Quarter ends et UNIX timestamp $QUARTER_END ($YEAR-$END)"