Skip to content

Commit 317f90c

Browse files
Copilotpnguyen215
andauthored
Improve error messages and clarify SundaySafe documentation
- Add guidance to error message for missing time formats - Update SundaySafe documentation to accurately describe upcoming Sunday behavior Agent-Logs-Url: https://github.com/sivaosorg/timefy/sessions/0772df36-2c23-49e6-a98c-f8ff5a636e5c Co-authored-by: pnguyen215 <39581473+pnguyen215@users.noreply.github.com>
1 parent dd8c368 commit 317f90c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

time.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,15 +910,19 @@ func (t *Timex) SaturdaySafe(s ...string) (time.Time, error) {
910910
return t.weekdaySafe("Saturday", 6, s...)
911911
}
912912

913-
// SundaySafe returns a new time.Time value representing the most recent or upcoming Sunday
913+
// SundaySafe returns a new time.Time value representing the upcoming Sunday
914914
// based on the provided date string(s) or the current date if no date strings are provided.
915915
// Unlike Sunday(), this method returns an error instead of panicking on parse failures.
916916
//
917+
// Note: This method uses the same algorithm as the other weekday methods but with an offset
918+
// calculation that always returns a future Sunday (or today if it's already Sunday at midnight).
919+
// If the current day is Sunday, it returns the next Sunday (7 days later).
920+
//
917921
// Parameters:
918922
// - s ...string: Optional date string(s) to parse; if none are provided, it defaults to today.
919923
//
920924
// Returns:
921-
// - A `time.Time` value representing the date and time at the start of the most recent or upcoming Sunday.
925+
// - A `time.Time` value representing the date and time at the start of the upcoming Sunday.
922926
// - An error if parsing fails.
923927
func (t *Timex) SundaySafe(s ...string) (time.Time, error) {
924928
var parseTime time.Time
@@ -1401,7 +1405,7 @@ func (t *Timex) IsFuture() bool {
14011405
func (t *Timex) parseWithFormat(s string, location *time.Location) (v time.Time, err error) {
14021406
formats := t.getTimeFormats()
14031407
if len(formats) == 0 {
1404-
err = fmt.Errorf("timefy: no time formats configured for parsing %q", s)
1408+
err = fmt.Errorf("timefy: no time formats configured for parsing %q; ensure Timex is created via With() or NewRule().With()", s)
14051409
return
14061410
}
14071411
for _, format := range formats {

0 commit comments

Comments
 (0)