Skip to content

Instantly share code, notes, and snippets.

@trauber
Created February 24, 2020 02:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?

Bash for Times to Use with Remind

# Calculate number of minutes since start of day.
# Use this with output of `remind -s` to calculate
# task duration.

GENERIC_DATE=$(date +'%b %d %Z %Y') # Example output: "Feb 23 EST 2020"
START_OF_DAY_IN_SECONDS_SINCE_THE_EPOCH=$(date --date="$GENERIC_DATE" +'%s') # That date spec provides sste at midnight.
NOW_IN_SECONDS_SINCE_THE_EPOCH=$(date +'%s')
SECONDS_SINCE_START_OF_DAY=$(( $NOW_IN_SECONDS_SINCE_THE_EPOCH - $START_OF_DAY_IN_SECONDS_SINCE_THE_EPOCH  ))
MINUTES_SINCE_START_OF_DAY=$(( $SECONDS_SINCE_START_OF_DAY / 60 ))

echo $MINUTES_SINCE_START_OF_DAY

###################

START_OF_TASK=$(rem -s | tail -1 | cut -d" " -f5)

echo $START_OF_TASK

DURATION_OF_TASK_IN_MINUTES=$(( $MINUTES_SINCE_START_OF_DAY - $START_OF_TASK ))


echo $DURATION_OF_TASK_IN_MINUTES


#########

REMIND_START="REM $(date +'%d %b %Y AT %H:%M') MSG <some string>"

echo $REMIND_START
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment