Skip to content

Commit 370e421

Browse files
committed
Support flexible time formats, 1.7.5
- Add normalizeDurationString function to handle formats like 1h30min, 1h 30m, 1h15min - Replace 'min' with 'm', 'hour'/'hr' with 'h', and remove spaces - Update version to 1.7.5
1 parent 25d581c commit 370e421

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.7.5 (2025-09-11)
2+
3+
### Fixed
4+
- Improve time parsing to support flexible formats like "1h30min", "1h 30m", "1h15min", "1h30m"
5+
16
## 1.7.4 (2025-09-11)
27

38
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<a href="https://goreportcard.com/report/github.com/ronilaukkarinen/focus"><img src="https://goreportcard.com/badge/github.com/ronilaukkarinen/focus" alt="GoReportCard"></a>
99
<a href="https://github.com/ronilaukkarinen/focus"><img src="https://img.shields.io/badge/go-1.24-blue.svg" alt="Go version"></a>
1010
<a href="https://github.com/ronilaukkarinen/focus/blob/master/LICENCE"><img src="https://img.shields.io/github/license/ronilaukkarinen/focus.svg" alt="LICENCE"></a>
11-
<a href="https://github.com/ronilaukkarinen/focus/releases/"><img src="https://img.shields.io/badge/version-1.7.4-blue.svg" alt="Latest release"></a>
11+
<a href="https://github.com/ronilaukkarinen/focus/releases/"><img src="https://img.shields.io/badge/version-1.7.5-blue.svg" alt="Latest release"></a>
1212
</p>
1313

1414
<h1 align="center">Focus on your task - with flow timer!</h1>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ronilaukkarinen/focus",
3-
"version": "1.7.4",
3+
"version": "1.7.5",
44
"description": "Focus is a flexible command-line productivity timer with flow mode for uninterrupted work sessions",
55
"main": "",
66
"repository": "https://github.com/ronilaukkarinen/focus",

timer/timer.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os"
1414
"os/exec"
1515
"path/filepath"
16+
"strings"
1617
"time"
1718

1819
"github.com/adrg/xdg"
@@ -409,10 +410,29 @@ func (t *Timer) promptFlowModeInfo() tea.Cmd {
409410
return t.soundForm.Init()
410411
}
411412

413+
// normalizeDurationString normalizes various time formats to Go's duration format
414+
func normalizeDurationString(s string) string {
415+
// Replace common variations with standard format
416+
result := s
417+
418+
// Replace "min" with "m"
419+
result = strings.ReplaceAll(result, "min", "m")
420+
421+
// Replace "hour" or "hr" with "h"
422+
result = strings.ReplaceAll(result, "hour", "h")
423+
result = strings.ReplaceAll(result, "hr", "h")
424+
425+
// Remove spaces between number and unit (e.g., "1h 30m" -> "1h30m")
426+
result = strings.ReplaceAll(result, " ", "")
427+
428+
return result
429+
}
430+
412431
// initFlowTimer initializes the timer in flow mode (counting up)
413432
func (t *Timer) initFlowTimer() error {
414-
// Parse the estimated time string
415-
dur, err := time.ParseDuration(t.estimatedTimeStr)
433+
// Parse the estimated time string with normalization
434+
normalizedTime := normalizeDurationString(t.estimatedTimeStr)
435+
dur, err := time.ParseDuration(normalizedTime)
416436
if err != nil {
417437
// Default to 25 minutes if parsing fails
418438
dur = 25 * time.Minute

0 commit comments

Comments
 (0)