Debian Codegraph @

date-calc.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # date-calc.sh
3 # Author: Nathan Coulter
4 # Used in ABS Guide with permission (thanks!).
5
6 MPHR=60 # Minutes per hour.
7 HPD=24 # Hours per day.
8
9 diffscip-shell shell abs-guide 10-4 diff(). () {
10 printfscip-shell system . . printf. '%s' $(( $(datescip-shell system . . date. -u -d"$TARGET" +%s) -
11 $(datescip-shell system . . date. -u -d"$CURRENT" +%s)))
12 # %d = day of month.
13 }
14
15
16 CURRENT=$(datescip-shell system . . date. -u -d '2007-09-01 17:30:24' '+%F %T.%N %Z')
17 TARGET=$(datescip-shell system . . date. -u -d'2007-12-25 12:30:00' '+%F %T.%N %Z')
18 # %F = full date, %T = %H:%M:%S, %N = nanoseconds, %Z = time zone.
19
20 printfscip-shell system . . printf. '\nInscip-shell system . . date. 2007, %s ' \
21 "$(date -d"scip-shell shell abs-guide 10-4 diff().$CURRENT +
22 $(( $(diff) /$MPHR /$MPHR /$HPD / 2 )) days" '+%d %B')"
23 # %B = name of month ^ halfway
24 printfscip-shell system . . printf. 'was halfway between %s ' "$(datescip-shell system . . date. -d"$CURRENT" '+%d %B')"
25 printfscip-shell system . . printf. 'and %s\n' "$(datescip-shell system . . date. -d"$TARGET" '+%d %B')"
26
27 printfscip-shell system . . printf. '\nOnscip-shell system . . date. %s at %s, there were\n' \
28 $(date -u -d"$CURRENT" +%F) $(datescip-shell system . . date. -u -d"$CURRENT" +%T)
29 DAYS=$(( $(diffscip-shell shell abs-guide 10-4 diff().) / $MPHR / $MPHR / $HPD ))
30 CURRENT=$(datescip-shell system . . date. -d"$CURRENT +$DAYS days" '+%F %T.%N %Z')
31 HOURS=$(( $(diffscip-shell shell abs-guide 10-4 diff().) / $MPHR / $MPHR ))
32 CURRENT=$(datescip-shell system . . date. -d"$CURRENT +$HOURS hours" '+%F %T.%N %Z')
33 MINUTES=$(( $(diffscip-shell shell abs-guide 10-4 diff().) / $MPHR ))
34 CURRENT=$(datescip-shell system . . date. -d"$CURRENT +$MINUTES minutes" '+%F %T.%N %Z')
35 printfscip-shell system . . printf. '%s days, %s hours, ' "$DAYS" "$HOURS"
36 printfscip-shell system . . printf. '%s minutes, and %s seconds ' "$MINUTES" "$(diffscip-shell shell abs-guide 10-4 diff().)"
37 printfscip-shell system . . printf. 'until Christmas Dinner!\n\n'
38
39 # Exercise:
40 # --------
41 # Rewrite the diff () function to accept passed parameters,
42 #+ rather than using global variables.