Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
version: 3

tasks:
run:
cmds:
- go run main.go

build:
cmds:
- go build

test:
cmds:
- go test
25 changes: 14 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ func tick() tea.Cmd {
}

type model struct {
zones []*Zone
now time.Time
hour int
showDates bool
interactive bool
isMilitary bool
zones []*Zone
now time.Time
hour int
showDates bool
interactive bool
isMilitary bool
isTwelveHour bool
}

func (m model) Init() tea.Cmd {
Expand Down Expand Up @@ -107,6 +108,7 @@ func main() {
when := flag.Int64("when", 0, "time in seconds since unix epoch")
doSearch := flag.Bool("list", false, "list zones by name")
military := flag.Bool("m", false, "use 24-hour time")
twelveHour := flag.Bool("t", false, "use 12-hour time")
flag.Parse()

if *showVersion == true {
Expand All @@ -133,11 +135,12 @@ func main() {
os.Exit(2)
}
var initialModel = model{
zones: config.Zones,
now: Now.Time(),
hour: Now.Time().Hour(),
showDates: false,
isMilitary: *military,
zones: config.Zones,
now: Now.Time(),
hour: Now.Time().Hour(),
showDates: false,
isMilitary: *military,
isTwelveHour: *twelveHour,
}

initialModel.interactive = !*exitQuick
Expand Down
30 changes: 27 additions & 3 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,24 @@ func (m model) View() string {

dateChanged := false
for i := startHour; i < startHour+24; i++ {
hour := ((i % 24) + 24) % 24 // mod 24
out := termenv.String(fmt.Sprintf("%2d", hour))
var hour int
var period string

// switch AM/PM vs 24-hour in future view
if m.isTwelveHour {
hour = ((i % 24) + 24) % 12
if hour == 0 {
hour = 12
}
if i%24 >= 12 {
period = "PM"
} else {
period = " "
}
} else {
hour = ((i % 24) + 24) % 24 // mod 24
}
out := termenv.String(fmt.Sprintf("%2d%s", hour, period))

out = out.Foreground(term.Color(hourColorCode(hour)))
// Cursor
Expand All @@ -64,12 +80,20 @@ func (m model) View() string {
if hour == 0 {
dates.WriteString(formatDayChange(&m, zone))
dateChanged = true
} else if hour == 12 && period != "PM" {
dates.WriteString(formatDayChange(&m, zone))
dateChanged = true
}
if !dateChanged {

// handle the spacing for the date/calendar icon
if !dateChanged && !m.isTwelveHour {
dates.WriteString(" ")
} else if m.isTwelveHour && !dateChanged {
dates.WriteString(" ")
}
}

// switch current timestamp from 12 to 24 hour
var datetime string
if m.isMilitary {
datetime = zone.ShortMT()
Expand Down