Skip to content

Commit a3b9d41

Browse files
committed
feat: Add weekendDays property and initialize it as DefaultWeekendDays
1 parent 35fc5c3 commit a3b9d41

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

carbon.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ import (
1212
"time"
1313
)
1414

15+
type StdTime = time.Time
16+
type Weekday = time.Weekday
17+
type Location = time.Location
18+
1519
// Carbon defines a Carbon struct.
1620
// 定义 Carbon 结构体
1721
type Carbon struct {
18-
time time.Time
22+
time StdTime
1923
layout string
20-
weekStartsAt time.Weekday
21-
weekendDays []time.Weekday
22-
loc *time.Location
24+
weekStartsAt Weekday
25+
weekendDays []Weekday
26+
loc *Location
2327
lang *Language
2428
Error error
2529
}
@@ -30,7 +34,8 @@ func NewCarbon(time ...time.Time) *Carbon {
3034
c := new(Carbon)
3135
c.lang = NewLanguage().SetLocale(DefaultLocale)
3236
c.layout = DefaultLayout
33-
c.weekStartsAt = weekdays[DefaultWeekStartsAt]
37+
c.weekStartsAt = DefaultWeekStartsAt
38+
c.weekendDays = DefaultWeekendDays
3439
if len(time) > 0 {
3540
c.time = time[0]
3641
c.loc = c.time.Location()
@@ -48,6 +53,7 @@ func (c *Carbon) Copy() *Carbon {
4853
newCarbon.time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc)
4954
newCarbon.layout = c.layout
5055
newCarbon.weekStartsAt = c.weekStartsAt
56+
newCarbon.weekendDays = c.weekendDays
5157
newCarbon.loc = c.loc
5258
newCarbon.Error = c.Error
5359

carbon_example_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func ExampleCarbon_Copy() {
3838
oldCarbon := carbon.Parse("2020-08-05")
3939
newCarbon := oldCarbon.Copy()
4040

41-
oldCarbon = oldCarbon.AddDay().SetLayout(carbon.DateTimeLayout).SetLocale("zh-CN").SetWeekStartsAt(carbon.Monday)
41+
oldCarbon = oldCarbon.AddDay().SetLayout(carbon.DateTimeLayout).SetLocale("zh-CN").SetWeekStartsAt(carbon.Sunday)
4242

4343
fmt.Printf("old time: %s\n", oldCarbon.ToString())
4444
fmt.Printf("new time: %s\n", newCarbon.ToString())
@@ -59,6 +59,6 @@ func ExampleCarbon_Copy() {
5959
// new layout: 2006-01-02
6060
// old locale: zh-CN
6161
// new locale: en
62-
// old week starts at: Monday
63-
// new week starts at: Sunday
62+
// old week starts at: Sunday
63+
// new week starts at: Monday
6464
}

0 commit comments

Comments
 (0)