mirror of
https://github.com/duke-git/lancet.git
synced 2025-12-19 17:02:23 +08:00
doc: update example link for BeginOfWeek and EndOfWeek
This commit is contained in:
@@ -535,7 +535,7 @@ import "github.com/duke-git/lancet/v2/datetime"
|
||||
[[play](https://go.dev/play/p/94m_UT6cWs9)]
|
||||
- **<big>BeginOfWeek</big>** : return the date time at the begin of week of specific date.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#BeginOfWeek)]
|
||||
[[play](https://go.dev/play/p/ynjoJPz7VNV)]
|
||||
[[play](https://go.dev/play/p/DCHdcL6gnfV)]
|
||||
- **<big>BeginOfMonth</big>** : return the date time at the begin of month of specific date.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#BeginOfMonth)]
|
||||
[[play](https://go.dev/play/p/bWXVFsmmzwL)]
|
||||
@@ -553,7 +553,7 @@ import "github.com/duke-git/lancet/v2/datetime"
|
||||
[[play](https://go.dev/play/p/eMBOvmq5Ih1)]
|
||||
- **<big>EndOfWeek</big>** : return the date time at the end of week of specific date.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#EndOfWeek)]
|
||||
[[play](https://go.dev/play/p/i08qKXD9flf)]
|
||||
[[play](https://go.dev/play/p/mGSA162YgX9)]
|
||||
- **<big>EndOfMonth</big>** : return the date time at the end of month of specific date.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#EndOfMonth)]
|
||||
[[play](https://go.dev/play/p/_GWh10B3Nqi)]
|
||||
|
||||
@@ -536,7 +536,7 @@ import "github.com/duke-git/lancet/v2/datetime"
|
||||
[[play](https://go.dev/play/p/94m_UT6cWs9)]
|
||||
- **<big>BeginOfWeek</big>** : 返回指定时间的每周开始时间,默认开始时间星期日。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#BeginOfWeek)]
|
||||
[[play](https://go.dev/play/p/ynjoJPz7VNV)]
|
||||
[[play](https://go.dev/play/p/DCHdcL6gnfV)]
|
||||
- **<big>BeginOfMonth</big>** : 返回指定时间的当月开始时间。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#BeginOfMonth)]
|
||||
[[play](https://go.dev/play/p/bWXVFsmmzwL)]
|
||||
@@ -554,7 +554,7 @@ import "github.com/duke-git/lancet/v2/datetime"
|
||||
[[play](https://go.dev/play/p/eMBOvmq5Ih1)]
|
||||
- **<big>EndOfWeek</big>** : 返回指定时间的星期结束时间,默认结束时间星期六。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#EndOfWeek)]
|
||||
[[play](https://go.dev/play/p/i08qKXD9flf)]
|
||||
[[play](https://go.dev/play/p/mGSA162YgX9)]
|
||||
- **<big>EndOfMonth</big>** : 返回指定时间的月份结束时间。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#EndOfMonth)]
|
||||
[[play](https://go.dev/play/p/_GWh10B3Nqi)]
|
||||
|
||||
@@ -280,7 +280,7 @@ func EndOfDay(t time.Time) time.Time {
|
||||
}
|
||||
|
||||
// BeginOfWeek return beginning week, default week begin from Sunday.
|
||||
// Play: https://go.dev/play/p/ynjoJPz7VNV
|
||||
// Play: https://go.dev/play/p/DCHdcL6gnfV
|
||||
func BeginOfWeek(t time.Time, beginFrom time.Weekday) time.Time {
|
||||
y, m, d := t.AddDate(0, 0, int(beginFrom-t.Weekday())).Date()
|
||||
beginOfWeek := time.Date(y, m, d, 0, 0, 0, 0, t.Location())
|
||||
@@ -291,7 +291,7 @@ func BeginOfWeek(t time.Time, beginFrom time.Weekday) time.Time {
|
||||
}
|
||||
|
||||
// EndOfWeek return end week time, default week end with Saturday.
|
||||
// Play: https://go.dev/play/p/i08qKXD9flf
|
||||
// Play: https://go.dev/play/p/mGSA162YgX9
|
||||
func EndOfWeek(t time.Time, endWith time.Weekday) time.Time {
|
||||
y, m, d := t.AddDate(0, 0, int(endWith-t.Weekday())).Date()
|
||||
var endWithWeek = time.Date(y, m, d, 23, 59, 59, int(time.Second-time.Nanosecond), t.Location())
|
||||
|
||||
@@ -741,7 +741,7 @@ func main() {
|
||||
func EndOfWeek(t time.Time, endWith time.Weekday) time.Time
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/i08qKXD9flf)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/mGSA162YgX9)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -551,7 +551,7 @@ func main() {
|
||||
func BeginOfWeek(t time.Time, beginFrom ...time.Weekday) time.Time
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ynjoJPz7VNV)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DCHdcL6gnfV)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -564,12 +564,13 @@ import (
|
||||
|
||||
func main() {
|
||||
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
|
||||
result := datetime.BeginOfWeek(input)
|
||||
|
||||
result := datetime.BeginOfWeek(input, time.Monday)
|
||||
|
||||
fmt.Println(result)
|
||||
|
||||
// Output:
|
||||
// 2023-01-08 00:00:00 +0000 UTC
|
||||
// 2023-01-02 00:00:00 +0000 UTC
|
||||
}
|
||||
```
|
||||
|
||||
@@ -743,7 +744,7 @@ func main() {
|
||||
func EndOfWeek(t time.Time, endWith ...time.Weekday) time.Time
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/i08qKXD9flf)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/mGSA162YgX9)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -756,12 +757,12 @@ import (
|
||||
|
||||
func main() {
|
||||
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
|
||||
result := datetime.EndOfWeek(input)
|
||||
result := datetime.EndOfWeek(input, time.Sunday)
|
||||
|
||||
fmt.Println(result)
|
||||
|
||||
// Output:
|
||||
// 2023-01-14 23:59:59.999999999 +0000 UTC
|
||||
// 2023-01-08 23:59:59.999999999 +0000 UTC
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user