Skip to content

Commit e045c61

Browse files
feat(civil): make civil a standalone module
Fixes #6275
1 parent c3273bb commit e045c61

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

civil/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Civil Time
2+
3+
[![Go Reference](https://pkg.go.dev/badge/cloud.google.com/go/civil.svg)](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.

civil/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module cloud.google.com/go/civil
2+
3+
go 1.25.0
4+
5+
require github.com/google/go-cmp v0.7.0

civil/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
2+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=

0 commit comments

Comments
 (0)