Updated code examples in README
This commit is contained in:
parent
da180f8af7
commit
00fa4d8d96
1 changed files with 7 additions and 4 deletions
11
README.md
11
README.md
|
|
@ -51,12 +51,15 @@ prevMonday := quando.Now().Prev(time.Monday)
|
||||||
start := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
start := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
end := time.Date(2028, 3, 15, 0, 0, 0, 0, time.UTC)
|
end := time.Date(2028, 3, 15, 0, 0, 0, 0, time.UTC)
|
||||||
duration := quando.Diff(start, end)
|
duration := quando.Diff(start, end)
|
||||||
fmt.Println(duration.Human()) // "2 years, 2 months, 14 days"
|
fmt.Println(duration.Human()) // "2 years, 2 months"
|
||||||
|
|
||||||
// Parsing (automatic format detection)
|
// Parsing (automatic format detection)
|
||||||
date, err := quando.Parse("2026-02-09")
|
date, err := quando.Parse("2026-02-09")
|
||||||
date, err := quando.Parse("09.02.2026") // EU format
|
date, err := quando.Parse("09.02.2026") // EU format
|
||||||
date, err := quando.Parse("3 days ago") // Relative
|
|
||||||
|
// Relative dates
|
||||||
|
date, err := quando.ParseRelative("+3 days") // 3 days from now
|
||||||
|
date, err = quando.ParseRelative("-1 week") // 1 week ago
|
||||||
|
|
||||||
// Formatting
|
// Formatting
|
||||||
date.Format(quando.ISO) // "2026-02-09"
|
date.Format(quando.ISO) // "2026-02-09"
|
||||||
|
|
@ -176,7 +179,7 @@ duration := end.Sub(start)
|
||||||
|
|
||||||
// quando: Built-in human formatting
|
// quando: Built-in human formatting
|
||||||
duration := quando.Diff(start, end)
|
duration := quando.Diff(start, end)
|
||||||
fmt.Println(duration.Human()) // "2 years, 2 months, 14 days" ✅
|
fmt.Println(duration.Human()) // "2 years, 2 months" ✅
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Start of Week (Monday)
|
#### Start of Week (Monday)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue