Created
April 11, 2019 09:38
-
-
Save j4rv/5f16f929a2ddcf4c59fe60f06a0c86af to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"time" | |
"github.com/fatih/color" | |
) | |
var startTime = time.Hour * 8 | |
var normalEndTime = time.Hour*18 + time.Minute*0 | |
var fridayEndTime = time.Hour*14 + time.Minute*30 | |
var summerEndTime = time.Hour*14 + time.Minute*30 | |
var progressPrinter = color.New(color.FgHiCyan) | |
func main() { | |
dayProgressCurr := int((currtime() - startTime).Minutes()) | |
dayProgressEnd := int((todaysEndTime() - startTime).Minutes()) | |
fmt.Println("Day progress...") | |
loadUntil( | |
dayProgressCurr/10, | |
dayProgressEnd/10, | |
) | |
fmt.Printf("%.1f hours left\n", float64(dayProgressEnd-dayProgressCurr)/60.0) | |
color.HiBlue("Not having caffeine for a month...") | |
loadUntil(time.Now().Day(), 30) | |
} | |
func currtime() time.Duration { | |
now := time.Now() | |
m, h := time.Duration(now.Minute()), time.Duration(now.Hour()) | |
return (time.Minute * m) + (time.Hour * h) | |
} | |
func todaysEndTime() time.Duration { | |
now := time.Now() | |
if now.Weekday() == time.Friday { | |
return fridayEndTime | |
} | |
m := now.Month() | |
if m == time.July || m == time.August || (m == time.September && now.Day() < 15) { | |
return summerEndTime | |
} | |
return normalEndTime | |
} | |
func loadUntil(n, max int) { | |
for i := 0; i <= n; i++ { | |
time.Sleep(time.Millisecond * 32) | |
progressPrinter.Printf("\r%s %d/%d", string(progressBar(i, max)), i, max) | |
} | |
fmt.Println() | |
if n == 30 { | |
fmt.Println("Done!") | |
} | |
} | |
func progressBar(actual, max int) []rune { | |
res := make([]rune, max+2) | |
res[0], res[max+1] = '[', ']' | |
for i := 1; i <= actual; i++ { | |
res[i] = '#' | |
} | |
for i := actual + 1; i < max+1; i++ { | |
res[i] = '-' | |
} | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment