Skip to content

Commit 01de308

Browse files
committed
♻️ refactor: update codebase #2
1 parent ac43ec8 commit 01de308

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,12 @@ import (
101101

102102
func main() {
103103
// time based on configuration
104-
location, _ := time.LoadLocation("Asia/Ho_Chi_Minh")
105-
conf := &timefy.Config{
106-
WeekStartDay: time.Monday,
107-
TimeLocation: location,
108-
TimeFormats: []string{"2006-01-02 15:04:05"},
109-
}
110-
t := time.Date(2025, 01, 15, 17, 51, 49, 123456789, time.Now().Location())
104+
rule := timefy.NewRule().WithLocationRFC(timefy.DefaultTimezoneVietnam)
105+
t = time.Date(2025, 01, 15, 17, 51, 49, 123456789, time.Now().Location())
111106
fmt.Println(t) // 2025-01-15 17:51:49.123456789 +0700 +07
112-
fmt.Println(conf.With(t).BeginningOfWeek()) // 2025-01-13 00:00:00 +0700 +07
113-
v, _ := conf.Parse("2005-11-12 22:14:01")
114-
fmt.Println(v) // 2005-11-12 22:14:01 +0700 +07
107+
fmt.Println(rule.With(t).BeginningOfWeek()) // 2025-01-12 00:00:00 +0700 +07
108+
v, _ := rule.Parse("2025-11-12 22:14:01")
109+
fmt.Println(v) // 2025-11-12 22:14:01 +0700 +07
115110
}
116111
```
117112

time.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,14 @@ func (t *Timex) FormatRFCshort(layout TimeRFC) string {
744744
return t.Time.Format(string(layout))
745745
}
746746

747+
// DefaultFormatRFC formats the time using a default layout that includes the date and time with nanosecond precision.
748+
//
749+
// Returns:
750+
// - A string representing the formatted time in the default RFC format.
751+
func (t *Timex) DefaultFormatRFC() string {
752+
return t.FormatRFC(TimeFormat20060102150405999999)
753+
}
754+
747755
// parseWithFormat attempts to parse a given date/time string `s` using a series of predefined formats
748756
// specified in the `TimeFormats` slice of the Timex instance. It tries to parse the string in the provided
749757
// `location` and returns the parsed time value or an error if parsing fails.

0 commit comments

Comments
 (0)