-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add plugin for time #215
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
19de33c
feat: add plugin for time
BenjaminGoehry 658cd52
wip
BenjaminGoehry 1eadcee
implement format and add test for it
BenjaminGoehry 1dc2d5e
implement parse and parse in location with tests
BenjaminGoehry e0081c4
wip
BenjaminGoehry f6135b0
add add features
BenjaminGoehry 88a168c
implement start of day
BenjaminGoehry ed3b20f
add test for start of day and add readme
BenjaminGoehry bacf3d1
modify llms.txt to take into account time pluggin
BenjaminGoehry b9c922b
change back to ancient
BenjaminGoehry 730ceb3
fix
BenjaminGoehry 368163d
fix
BenjaminGoehry 3ecc6ec
fix
BenjaminGoehry 1ca331a
fix
BenjaminGoehry bfe4efa
fix
BenjaminGoehry a889d79
fix
BenjaminGoehry 7293ebe
fix
BenjaminGoehry 016bdf8
fix
BenjaminGoehry 015a8d0
fix
BenjaminGoehry a61e03e
fix
BenjaminGoehry 74fbd7d
fix'
BenjaminGoehry 507172b
remove replace and update version
BenjaminGoehry 2843e3b
fix
BenjaminGoehry c3758e3
fix
BenjaminGoehry dcb74f9
fix
BenjaminGoehry 4a71e01
resolve reviews
BenjaminGoehry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| # Time Plugin | ||
|
|
||
| The time plugin provides operators for manipulating dates/time object in reactive streams. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| go get github.com/samber/ro/plugins/time | ||
| ``` | ||
|
|
||
| ## Operators | ||
|
|
||
| ### Add | ||
|
|
||
| Add a duration to a date | ||
|
|
||
| ```go | ||
| import ( | ||
| "github.com/samber/ro" | ||
| rotime "github.com/samber/ro/plugins/time" | ||
| ) | ||
|
|
||
| observable := ro.Pipe1( | ||
| ro.Just( | ||
| time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC), | ||
| time.Date(0, time.January, 1, 23, 59, 59, 0, time.UTC), | ||
| ), | ||
| rotime.Add(2 * time.Hour), | ||
| ) | ||
|
|
||
| // Output: | ||
| // Next: time.Date(2026, time.January, 7, 16, 30, 0, 0, time.UTC) | ||
| // Next: time.Date(0, time.January, 2, 1, 59, 59, 0, time.UTC) | ||
| // Completed | ||
| ``` | ||
|
|
||
| ### AddDate | ||
|
|
||
| Add a duration defined by years, months, days to a date. | ||
|
|
||
| ```go | ||
| import ( | ||
| "github.com/samber/ro" | ||
| rotime "github.com/samber/ro/plugins/time" | ||
| ) | ||
|
|
||
| observable := ro.Pipe1( | ||
| ro.Just( | ||
| time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC), | ||
| ), | ||
| rotime.AddDate(0, 1, 0), | ||
| ) | ||
|
|
||
| // Output: | ||
| // Next: time.Date(2026, time.February, 7, 14, 30, 0, 0, time.UTC) | ||
| // Completed | ||
| ``` | ||
|
|
||
| ### Format | ||
|
|
||
| Transform an observable time.Time into a string, formatted according to the provided layout. | ||
|
|
||
| ```go | ||
| import ( | ||
| "github.com/samber/ro" | ||
| rotime "github.com/samber/ro/plugins/time" | ||
| ) | ||
|
|
||
| observable := ro.Pipe1( | ||
| ro.Just( | ||
| time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC), | ||
| ), | ||
| rotime.Format("2006-01-02 15:04:05"), | ||
| ) | ||
|
|
||
| // Output: | ||
| // Next: "2026-01-07 14:30:00" | ||
| // Completed | ||
| ``` | ||
|
|
||
| ### In | ||
|
|
||
| Transform an observable time.Time into a string, formatted according to the provided layout. | ||
|
|
||
| ```go | ||
| import ( | ||
| "github.com/samber/ro" | ||
| rotime "github.com/samber/ro/plugins/time" | ||
| ) | ||
|
|
||
| observable := ro.Pipe1( | ||
| ro.Just( | ||
| time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC), | ||
| ), | ||
| rotime.In(time.LoadLocation("Europe/Paris")), | ||
| ) | ||
|
|
||
| // Output: | ||
| // Next: time.Date(2026, time.January, 7, 16, 30, 0, 0, time.CET), | ||
| // Completed | ||
| ``` | ||
|
|
||
| ### Parse | ||
|
|
||
| Transform an observable string into an observable of time.Time. | ||
|
|
||
| ```go | ||
| import ( | ||
| "github.com/samber/ro" | ||
| rotime "github.com/samber/ro/plugins/time" | ||
| ) | ||
|
|
||
| observable := ro.Pipe1( | ||
| ro.Just( | ||
| "2026-01-07 14:30:00", | ||
| ), | ||
| rotime.Parse("2006-01-02 15:04:05"), | ||
| ) | ||
|
|
||
| // Output: | ||
| // Next: time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC) | ||
| // Completed | ||
| ``` | ||
|
|
||
| ### ParseInLocation | ||
|
|
||
| Transform an observable string into an observable of time.Time, using location. | ||
|
|
||
| ```go | ||
| import ( | ||
| "github.com/samber/ro" | ||
| rotime "github.com/samber/ro/plugins/time" | ||
| ) | ||
|
|
||
| observable := ro.Pipe1( | ||
| ro.Just( | ||
| "2026-01-07 14:30:00", | ||
| ), | ||
| rotime.ParseInLocation("2006-01-02 15:04:05", time.UTC), | ||
| ) | ||
|
|
||
| // Output: | ||
| // Next: time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC) | ||
| // Completed | ||
| ``` | ||
|
|
||
| ### StartOfDay | ||
|
|
||
| Truncates the time to the beginning of its day in the local time zone | ||
|
|
||
| ```go | ||
| import ( | ||
| "github.com/samber/ro" | ||
| rotime "github.com/samber/ro/plugins/time" | ||
| ) | ||
|
|
||
| observable := ro.Pipe1( | ||
| ro.Just( | ||
| time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC), | ||
| ), | ||
| rotime.StartOfDay(), | ||
| ) | ||
|
|
||
| // Output: | ||
| // Next: time.Date(2026, time.January, 7, 0, 0, 0, 0, time.UTC) | ||
| // Completed | ||
| ``` | ||
|
|
||
| ## Performance Considerations | ||
| - The time plugin uses Go's standard `time` package for operations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| module github.com/samber/ro/plugins/time | ||
|
|
||
| go 1.18 | ||
|
|
||
| require ( | ||
| github.com/samber/ro v0.2.0 | ||
| github.com/stretchr/testify v1.11.1 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/samber/lo v1.52.0 // indirect | ||
| golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect | ||
| golang.org/x/text v0.22.0 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||
| github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= | ||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw= | ||
| github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0= | ||
| github.com/samber/ro v0.2.0 h1:pwhLFGZprz+3KyE3JIUnv8GGF/ADpIpvFUEDxuzfGbY= | ||
| github.com/samber/ro v0.2.0/go.mod h1:eInj5R1BbXfGoT1ef0HIO5Qie0wlPkkyL0koOaEmfNM= | ||
| github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= | ||
| github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= | ||
| golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= | ||
| golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= | ||
| golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= | ||
| golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= | ||
| gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
| gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright 2025 samber. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://github.com/samber/ro/blob/main/licenses/LICENSE.apache.md | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package rotime | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/samber/ro" | ||
| ) | ||
|
|
||
| // Add returns an operator that adds a fixed duration to each time value. | ||
| // | ||
| // Example: | ||
| // | ||
| // obs := ro.Pipe1( | ||
| // ro.Just(time.Now()), | ||
| // rotime.Add(2*time.Hour), | ||
| // ) | ||
| // | ||
| // The observable then emits: time.Now().Add(2 * time.Hour). | ||
| func Add(d time.Duration) func(destination ro.Observable[time.Time]) ro.Observable[time.Time] { | ||
samber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ro.Map( | ||
| func(value time.Time) time.Time { | ||
| return value.Add(d) | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| // AddDate returns an operator that adds a date offset (years, months, days) to each time value. | ||
| // | ||
| // Example: | ||
| // | ||
| // obs := ro.Pipe1( | ||
| // ro.Just(time.Date(2026, time.January, 7, 14, 30, 0, 0, time.UTC)), | ||
| // rotime.AddDate(0, 1, 0), | ||
| // ) | ||
| // | ||
| // The observable then emits: time.Date(2026, time.February, 7, 14, 30, 0, 0, time.UTC). | ||
| func AddDate(years int, months int, days int) func(destination ro.Observable[time.Time]) ro.Observable[time.Time] { | ||
| return ro.Map( | ||
| func(value time.Time) time.Time { | ||
| return value.AddDate(years, months, days) | ||
| }, | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.