|
| 1 | +# Civil Time |
| 2 | + |
| 3 | +[](https://pkg.go.dev/cloud.google.com/go/civil) |
| 4 | + |
| 5 | +Go package for civil time: a time-zone-independent representation of time that |
| 6 | +follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, |
| 7 | +60-minute hours, and 60-second minutes. |
| 8 | + |
| 9 | +## Install |
| 10 | + |
| 11 | +```bash |
| 12 | +go get cloud.google.com/go/civil |
| 13 | +``` |
| 14 | + |
| 15 | +## Stability |
| 16 | + |
| 17 | +The stability of this module is indicated by SemVer. |
| 18 | + |
| 19 | +## Example |
| 20 | + |
| 21 | +```go |
| 22 | +import ( |
| 23 | + "fmt" |
| 24 | + "time" |
| 25 | + |
| 26 | + "cloud.google.com/go/civil" |
| 27 | +) |
| 28 | + |
| 29 | +// Working with dates |
| 30 | +d := civil.Date{Year: 2024, Month: time.March, Day: 15} |
| 31 | +fmt.Println(d) // 2024-03-15 |
| 32 | +fmt.Println(d.AddDays(10)) // 2024-03-25 |
| 33 | +fmt.Println(d.Weekday()) // Friday |
| 34 | + |
| 35 | +parsed, _ := civil.ParseDate("2024-03-15") |
| 36 | +fmt.Println(parsed == d) // true |
| 37 | + |
| 38 | +today := civil.DateOf(time.Now()) |
| 39 | +fmt.Println(today.After(d)) // depends on current date |
| 40 | + |
| 41 | +// Working with times |
| 42 | +t := civil.Time{Hour: 14, Minute: 30, Second: 0} |
| 43 | +fmt.Println(t) // 14:30:00 |
| 44 | + |
| 45 | +// Working with datetimes |
| 46 | +dt := civil.DateTime{Date: d, Time: t} |
| 47 | +fmt.Println(dt) // 2024-03-15T14:30:00 |
| 48 | + |
| 49 | +// Convert to time.Time in a specific location |
| 50 | +loc, _ := time.LoadLocation("Europe/Berlin") |
| 51 | +tt := dt.In(loc) |
| 52 | +fmt.Println(tt) // 2024-03-15 14:30:00 +0100 CET |
| 53 | +``` |
| 54 | + |
| 55 | +## Go Version Support |
| 56 | + |
| 57 | +See the [Go Versions Supported](https://github.com/googleapis/google-cloud-go#go-versions-supported) |
| 58 | +section in the root directory's README. |
| 59 | + |
| 60 | +## Contributing |
| 61 | + |
| 62 | +Contributions are welcome. Please, see the [CONTRIBUTING](https://github.com/GoogleCloudPlatform/google-cloud-go/blob/main/CONTRIBUTING.md) |
| 63 | +document for details. |
| 64 | + |
| 65 | +Please note that this project is released with a Contributor Code of Conduct. |
| 66 | +By participating in this project you agree to abide by its terms. See |
| 67 | +[Contributor Code of Conduct](https://github.com/GoogleCloudPlatform/google-cloud-go/blob/main/CONTRIBUTING.md#contributor-code-of-conduct) |
| 68 | +for more information. |
0 commit comments