Skip to content

Commit 543e5f2

Browse files
committedFeb 26, 2025
feat: add CurrentLayout method
1 parent a520aea commit 543e5f2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
 

‎getter.go

+6
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,9 @@ func (c Carbon) Age() int {
431431
}
432432
return int(c.DiffInYears(now))
433433
}
434+
435+
// CurrentLayout returns the layout used for parsing the time string.
436+
// 获取当前布局模板
437+
func (c Carbon) CurrentLayout() string {
438+
return c.layout
439+
}

‎getter_unit_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -1648,3 +1648,28 @@ func TestCarbon_Age(t *testing.T) {
16481648
})
16491649
}
16501650
}
1651+
1652+
func TestCarbon_CurrentLayout(t *testing.T) {
1653+
tests := []struct {
1654+
name string
1655+
carbon Carbon
1656+
want string
1657+
}{
1658+
{
1659+
name: "case1",
1660+
carbon: ParseByLayout("now", DateTimeLayout),
1661+
want: DateTimeLayout,
1662+
},
1663+
{
1664+
name: "case2",
1665+
carbon: ParseByLayout("2025-02-26", DateLayout),
1666+
want: DateLayout,
1667+
},
1668+
}
1669+
1670+
for _, tt := range tests {
1671+
t.Run(tt.name, func(t *testing.T) {
1672+
assert.Equalf(t, tt.want, tt.carbon.CurrentLayout(), "CurrentLayout()")
1673+
})
1674+
}
1675+
}

0 commit comments

Comments
 (0)
Please sign in to comment.