Skip to content

Commit d3bc657

Browse files
committed
date documentation and tests
1 parent 21a3884 commit d3bc657

File tree

6 files changed

+794
-99
lines changed

6 files changed

+794
-99
lines changed

date/date.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
// - JSON marshalling/unmarshalling
1111
// - Nullable date support
1212
// - Time zone handling
13+
//
14+
// # Week Calculations
15+
//
16+
// This package uses github.com/jinzhu/now for week-related period boundary
17+
// calculations (BeginningOfWeek, EndOfWeek, LastMonday, NextSunday).
18+
// The package is statically configured with now.WeekStartDay = time.Monday
19+
// in the init() function to ensure Monday is treated as the first day of the week.
20+
//
21+
// TODO: remove dependency on github.com/jinzhu/now and add weekstart argument to the functions that need it
1322
package date
1423

1524
import (
@@ -27,6 +36,11 @@ import (
2736
"github.com/domonda/go-types/strutil"
2837
)
2938

39+
func init() {
40+
// Configure the now package for week-related operations
41+
now.WeekStartDay = time.Monday
42+
}
43+
3044
// Note: Date does not implement types.NormalizableValidator[Date] because
3145
// its Normalized() method accepts optional language.Code parameters.
3246
// This is intentional as it provides more functionality than the interface requires.
@@ -716,7 +730,7 @@ func (date *Date) Scan(value any) (err error) {
716730
return nil
717731
}
718732

719-
return fmt.Errorf("can't scan value '%#v' of type %T as data.Date", value, value)
733+
return fmt.Errorf("can't scan value '%#v' of type %T as date.Date", value, value)
720734
}
721735

722736
// Value implements the database/sql/driver.Valuer interface.

0 commit comments

Comments
 (0)