Skip to content

Commit

Permalink
Merge pull request #17 from merschformann/merschformann/fix-12h-align…
Browse files Browse the repository at this point in the history
…ment

Fixes 12h mode alignment
  • Loading branch information
merschformann authored Jan 11, 2025
2 parents acc076e + 7368c3d commit 5ad827a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ The configuration is stored in `$XDG_CONFIG_HOME/gotz/config.json` (usually `~/.
// Dynamic mode colors
// - tcell color names like crimson, green, etc.
// - hex codes like #DC143C, #00ff00, etc.
// Note that some symbols are not fully opaque and will show the background color, thus,
// making the color appear darker (or lighter for white/light terminal backgrounds)
"coloring": {
// Color of the morning segment for static mode
"StaticColorMorning": "#EC3620",
Expand Down
14 changes: 10 additions & 4 deletions core/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ type Plotter struct {

// formatTime formats the time in the default way (distinguishing 12/24 hours
// though).
func formatTime(twelve bool, t time.Time) string {
func formatTime(twelve, flush bool, t time.Time) string {
if twelve {
return t.Format("3:04PM")
// 12-hour format
s := t.Format("3:04PM")
if flush {
return fmt.Sprintf("%7s", s)
}
return s
} else {
// 24-hour format
return t.Format("15:04")
}
}
Expand Down Expand Up @@ -266,7 +272,7 @@ func PlotTime(plt Plotter, cfg Config, t time.Time) error {
headLine := strings.Repeat(" ",
timeInfoWidth+nowSlot-(len(nowTag)+1)) +
nowTag + " v " +
formatTime(cfg.Hours12, t)
formatTime(cfg.Hours12, false, t)
if len(headLine) > plt.TerminalWidth {
// Truncate head line if it is too long
headLine = headLine[:plt.TerminalWidth]
Expand Down Expand Up @@ -351,7 +357,7 @@ func createTimeInfos(cfg Config, t time.Time) (timeInfos []string, times []*time
"%s: %s %s",
timeInfo,
formatDay(cfg.Hours12, t.In(timeZones[i])),
formatTime(cfg.Hours12, t.In(timeZones[i])))
formatTime(cfg.Hours12, true, t.In(timeZones[i])))
timeInfos[i] = timeInfo
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/static_hours12.golden
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
now v 4:00PM
Local : Sat 24 Aug 1985 2:00PM |
Local : Sat 24 Aug 1985 2:00PM |
▒▒▒▒▒▒██████████████████|███████████▒▒▒▒▒▒▒▒▒▒▒▒
New York: Sat 24 Aug 1985 10:00AM |
▒▒▒▒▒▒██████|███████████████████████▒▒▒▒▒▒▒▒▒▒▒▒
Berlin : Sat 24 Aug 1985 4:00PM |
Berlin : Sat 24 Aug 1985 4:00PM |
▒▒▒▒▒▒████████████████████████|█████▒▒▒▒▒▒▒▒▒▒▒▒
Shanghai: Sat 24 Aug 1985 10:00PM |
████████████████████████▒▒▒▒▒▒▒▒▒▒▒▒| ▒▒▒▒▒▒██████
Expand Down

0 comments on commit 5ad827a

Please sign in to comment.