MCPcopy Index your code
hub / github.com/duke-git/lancet / ExampleAddDaySafe

Function ExampleAddDaySafe

datetime/datetime_example_test.go:93–116  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91}
92
93func ExampleAddDaySafe() {
94 leapYearDate1, _ := time.Parse("2006-01-02", "2024-02-29")
95 result1 := AddDaySafe(leapYearDate1, 1)
96
97 leapYearDate2, _ := time.Parse("2006-01-02", "2024-03-01")
98 result2 := AddDaySafe(leapYearDate2, -1)
99
100 nonLeapYearDate1, _ := time.Parse("2006-01-02", "2025-02-28")
101 result3 := AddDaySafe(nonLeapYearDate1, 1)
102
103 nonLeaYearDate2, _ := time.Parse("2006-01-02", "2025-03-01")
104 result4 := AddDaySafe(nonLeaYearDate2, -1)
105
106 fmt.Println(result1.Format("2006-01-02"))
107 fmt.Println(result2.Format("2006-01-02"))
108 fmt.Println(result3.Format("2006-01-02"))
109 fmt.Println(result4.Format("2006-01-02"))
110
111 // Output:
112 // 2024-03-01
113 // 2024-02-29
114 // 2025-03-01
115 // 2025-02-28
116}
117
118func ExampleAddMonthSafe() {
119 date1, _ := time.Parse("2006-01-02", "2025-01-31")

Callers

nothing calls this directly

Calls 2

AddDaySafeFunction · 0.85
FormatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…