Last active
March 14, 2019 22:15
-
-
Save curtmack/4ecdb7db9b6a273b6da1f36c1560f6f7 to your computer and use it in GitHub Desktop.
Sums time in Jira format and prints out the total number of hours.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
######################################################################### | |
# # | |
# Sums times in Jira format and prints out the total number of hours. # | |
# Include space to separate each number from its unit. # | |
# # | |
# Example usage: # | |
# # | |
# $ jira2hours 1 d 2 h 1 w 4 h 30 m # | |
# > 42.5 # | |
# # | |
######################################################################### | |
# Set to match your Jira team's time tracking settings | |
WORKING_DAYS_PER_WEEK=5 | |
WORKING_HOURS_PER_DAY=6 | |
PRELUDE="\ | |
: m + ; \ | |
: h 60 * m ; \ | |
: d $WORKING_HOURS_PER_DAY * h ; \ | |
: w $WORKING_DAYS_PER_WEEK * d ; \ | |
: start 0 ; \ | |
: finish s>f 60e0 f/ f. cr ;" | |
if [ -x "$FORTH" ] | |
then | |
# Unknown forth. Probably accepts commands over stdin. | |
forthexec() { | |
echo "$*" | $FORTH | |
} | |
elif [ -x "$(command -v gforth)" ] | |
then | |
# Use GNU forth | |
forthexec() { | |
gforth -e "$*" | |
} | |
elif [ -x "$(command -v pforth)" ] | |
then | |
# Use pForth | |
forthexec() { | |
echo "$*" | pforth | |
} | |
else | |
cat <<EOF | |
No Forth interpreter could be found. | |
Install GNU Forth (gforth) or set FORTH to point to a Forth interpreter. | |
EOF | |
exit 1 | |
fi | |
forthexec "$PRELUDE start $* finish bye" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment