Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borks if you're < 1 hour from Beer o'Clock #3

Open
cah-chrisembree opened this issue Jan 6, 2017 · 2 comments
Open

Borks if you're < 1 hour from Beer o'Clock #3

cah-chrisembree opened this issue Jan 6, 2017 · 2 comments

Comments

@cah-chrisembree
Copy link

I have some ugly hacks (too ugly to submit) that basically pass Seconds to beer_o_clock() as parameters. The If $2 -gt $1 still works and it eliminates the need for the datediff function.

local secs=$(date -d 'now' +"%s")
local beer_is_at=16
local beer_seconds=$(date -d "today ${beer_is_at}:00:00" '+%s')

And call with
case $day in
[1-5]*) beer_o_clock $beer_seconds $hrs;; # mon - fri

It makes this much cleaner too:
local hrsUntil=$(( ($1 - $2) / 60 / 60 ))
local minUntil=$(( ($1 - $2) / 60 ))

Just my $0.02. Was fun playing with this.

@hhsnopek
Copy link
Owner

Gonna check this out today!

@cah-chrisembree
Copy link
Author

cah-chrisembree commented Jan 11, 2017

I also discovered that you need to subtract out the large values for the countdown to make sense...

  local later=$1
  local hrsUntil=$(( ($later - $now) / 60 / 60 ))
  local minUntil=$(( ($later - $now - $hrsUntil * 3600) / 60 ))
  local secUntil=$(( ($later - $now - $hrsUntil * 3600 - $minUntil * 60) ))

Oh, the seconds were added by a co-worker suggestion. ;) We're having fun with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants