Skip to content

Commit

Permalink
Fix #3 Error when using different format
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Gaunet committed Jan 30, 2023
1 parent 6412837 commit 4b73a1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion calcdatelib/calcdatelib.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (d *Date) initIndexSecond() error {
func (d *Date) initUnitTime(defaultValue int, ptrToInit *int, ptrRelativToInit *int, idx int) error {
*ptrToInit = defaultValue
*ptrRelativToInit = 0
if idx != -1 {
if idx > 0 {
value := d.submatch[idx]
if value != "" {
convert, err := strconv.Atoi(value)
Expand Down
9 changes: 9 additions & 0 deletions calcdatelib/calcdatelib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ func TestNewDate(t *testing.T) {
expectedString: "1981/12/01 13:00:00",
expectedErr: false,
},
{
Name: "different format",
nowFct: func() time.Time { return time.Date(1982, 01, 01, 00, 00, 00, 0, time.UTC) }, // 1982-01-01 00:00:00
argDate: "2022/12/01",
argIfmt: "%YYYY/%MM/%DD",
argTz: "",
expectedString: "2022/12/01 00:00:00",
expectedErr: false,
},
}

for _, test := range testCases {
Expand Down

0 comments on commit 4b73a1d

Please sign in to comment.