-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for times without leading '0'
The web interface of clockify supports times in format HMM (1 digit for the hour and 2 digits for the minutes), for example 915 is 09:15.
- Loading branch information
Showing
2 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package timehlp_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/lucassabreu/clockify-cli/pkg/timehlp" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseTime(t *testing.T) { | ||
|
||
now := timehlp.Today() | ||
nowStr := now.Format("2006-01-02") | ||
|
||
t.Run("now", func(t *testing.T) { | ||
// this case is special because it is not deterministic | ||
parsed, err := timehlp.ConvertToTime("now") | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, nowStr, parsed.Format("2006-01-02")) | ||
|
||
}) | ||
|
||
tts := []struct { | ||
name string | ||
expected string | ||
toParse string | ||
}{ | ||
{name: "FullTimeFormat", expected: "09:59:01", toParse: fmt.Sprintf("%s %s", nowStr, "09:59:01")}, | ||
{name: "SimplerTimeFormat", expected: "09:59:00", toParse: fmt.Sprintf("%s %s", nowStr, "09:59")}, | ||
{name: "OnlyTimeFormat", expected: "16:03:02", toParse: "16:03:02"}, | ||
{name: "SimplerOnlyTimeFormat", expected: "16:03:00", toParse: "16:03"}, | ||
{name: "SimplerOnlyTimeFormat", expected: "06:03:00", toParse: "06:03"}, | ||
{name: "SimplerOnlyTimeFormatWL", expected: "06:03:00", toParse: "6:03"}, | ||
{name: "SimplestOnlyTimeFormat", expected: "16:03:00", toParse: "1603"}, | ||
{name: "SimplestOnlyTimeFormatWL", expected: "06:03:00", toParse: "603"}, | ||
} | ||
|
||
for _, tt := range tts { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
parsed, err := timehlp.ConvertToTime(tt.toParse) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, fmt.Sprintf("%s %s", nowStr, tt.expected), parsed.Format("2006-01-02 15:04:05")) | ||
}) | ||
} | ||
|
||
} |