Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
✨ Added shift tracker
Browse files Browse the repository at this point in the history
Use `--shift` argument to see how much is left of your shift.
  • Loading branch information
Beta Pictoris authored Feb 26, 2022
2 parents d7e7420 + 56e571c commit 9232a6c
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"time"

Expand All @@ -16,12 +18,42 @@ const (
)

func main() {
var mode = "day" // Mode can be 'day' or 'shift'

var hour = time.Now().Hour()
var minute = time.Now().Minute()
var minutesInADay = 1440.00
var length = 1440.

var shiftL = 8.0

// Check if --shift is in args
if len(os.Args) >= 2 {
if "--shift" == os.Args[1] {
if len(os.Args) >= 3 {
shiftL, _ = strconv.ParseFloat(os.Args[2], 64)
}
mode = "shift"
} else {
fmt.Println("Usage: timeleft [--shift [Shift length]]")
os.Exit(1)
}
}

if mode == "shift" {
c, b := exec.Command("uptime"), new(strings.Builder)
c.Stdout = b
c.Run()

var time = strings.Split(b.String(), " ")[1]

hour, _ = strconv.Atoi(strings.Split(time, ":")[0])
minute, _ = strconv.Atoi(strings.Split(time, ":")[1])

length = (shiftL * 60)
}

var time = float64(((hour * 60) + minute))
var per = float64(time / minutesInADay)
var per = float64(time / length)

prog(int(time), per)
}
Expand Down

0 comments on commit 9232a6c

Please sign in to comment.