feat(unitproc/bkt-replace_apos) Handle more replacement cases
[BK-2020-03.git] / user / calcGalTick.sh
1 #!/bin/bash
2 # Desc: Prints a list of galactic tick dates
3 # Usage: ./calcGalTick.sh [int start] [int end]
4 # Input: arg1: int start index
5 # arg2: int end index
6 # Example: ./calcGalTick.sh 0 250
7 # Depends: bc 1.07.1; date (GNU coreutils) 8.32
8 # Version: 0.0.2
9 # Ref/Attrib: [1] Galactic Tick Day Calendar. (2021-10-20). https://github.com/GalacticTick/GalacticTick.github.io/blob/master/documents/press-3.pdf
10
11 # Galactic Tick duration equation (seconds)
12 ## (Earth years per galactic turn) / (100ths of arcseconds per turn) * (solar days in Earth year)
13 sGalTickEq="(225 * 10^6) / (1296000 * 100) * (365.25) * (24*3600)";
14 #sGalTickEq="(225 * 10^6) / (1296000 * 100) * (365.24217) * (24*3600)";
15
16 # Galactic tick duration (seconds)
17 sGalTick="$(echo "$sGalTickEq" | bc -l)"; # 54788453.99999999999996457600
18 #sGalTick="$(printf "%.0f" "$sGalTick")"; # round to int
19
20 # Unix epoch of first tick (seconds; date Hans Lippershey patented the first telescope)
21 ueFirstTick="$(date --date="1608-10-02" +%s)";
22
23 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
24 die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
25 must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
26 printGalTickDate() {
27 # Usage: printGalTickDate [int]
28 # Input: arg1: nthGalTick int n'th observance since frist Galactic Tick
29 # var: sGalTick: int Galactic tick duration
30 # var: ueFirstTick: int Unix epoch of first tick
31 # Output: str: ISO-8601 date string
32 # Example: printGalTickDate 239
33 # 2023-09-09
34 # Depends: bc 1.07.1; date (GNU coreutils) 8.32
35 # Version: 0.0.1
36 local nthGalTick output;
37
38 # Calc Unix epoch of n'th observance since first Galactic Tick
39 ## 0th tick was first tick
40 nthGalTick="$1";
41 ueTickEq="( $ueFirstTick + ( ($nthGalTick - 0) * $sGalTick ) )";
42 ueTick="$( echo "$ueTickEq" | bc -l )";
43
44 # Print calendar date
45 #output="$(TZ=UTC date --date="@$ueTick" +%Y-%m-%dT%H:%M:%S%z)";
46 output="$(TZ=UTC date --date="@$ueTick" +%Y-%m-%d)";
47
48 printf "%s\n" "$output";
49 }; # print ISO-8601 calendar date of tick
50 main() {
51 start="$1";
52 end="$2";
53 for ((tick="$start"; tick<="$end"; tick++)); do
54 printf "%03d: " "$tick"; # observance number
55 printGalTickDate "$tick"; # date
56 done;
57 }; # main program
58
59 main "$@";
60
61 # Author: Steven Baltakatei Sandoval
62 # License: GPLv3+