Skip to content

Experiment #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: 1.21.x
- uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3
go-version: 1.23.x
- uses: actions/checkout@v4
- uses: golangci/golangci-lint-action@v6
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: 1.21.x
- uses: actions/checkout@v4
- run: go test -v -count 1 -tags parse ./...
integration:
name: integration
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.21.x
- uses: actions/checkout@v2
- run: go test -v -count 1 ./...
- uses: actions/checkout@v4
- run: go run main.go
working-directory: ./test/integration
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"go.lintTool": "golangci-lint"
"go.lintTool": "golangci-lint",
"go.buildTags": "parse"
}
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,28 @@ And parsing a time:

```golang
var time chrono.LocalTime
time.Parse("%H:%M:%S", "12:30:15")
fmt.Println(time.Parse("%H:%M:%S", "12:30:15"))
```

There are also predefined layouts, similar to the `time` package, but with the addition of layouts compatible with ISO 8601.

### Experimental: Parsing without a layout

The example above assumes that you know how a date time string is formatted, but that's not always the case. For these situations, `ParseToLayout` accepts just a string and attempts to parse it, also returning the layout string.

```golang
var c chrono.OffsetDateTime
fmt.Println(chrono.ParseToLayout(
"2006-04-09",
chrono.ParseConfig{},
&c,
)) // %Y-%m-%d
```

To access this function you need to build with `-tag parse`.

*This API is incomplete and subject to change until a stable release is reached.*

## Parse and format ISO 8601 durations

When interfacing with systems where the <code>time</code> package's duration formatting is not understood, ISO 8601 is a commonly-adopted standard.
Expand Down
4 changes: 2 additions & 2 deletions duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ func TestDuration_Parse(t *testing.T) {
}
}

t.Run("dots", func(t *testing.T) {
t.Run("dots", func(_ *testing.T) {
run()
})

t.Run("commas", func(t *testing.T) {
t.Run("commas", func(_ *testing.T) {
tt.input = strings.ReplaceAll(tt.input, ".", ",")
run()
})
Expand Down
4 changes: 2 additions & 2 deletions extent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func TestExtent_Parse(t *testing.T) {
}
}

t.Run("dots", func(t *testing.T) {
t.Run("dots", func(_ *testing.T) {
run()
})

t.Run("commas", func(t *testing.T) {
t.Run("commas", func(_ *testing.T) {
tt.input = strings.ReplaceAll(tt.input, ".", ",")
run()
})
Expand Down
Loading
Loading