-
Notifications
You must be signed in to change notification settings - Fork 0
Adds handling for half day OOO requests #34
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
6 commits
Select commit
Hold shift + click to select a range
628a581
Add handleAllDay and handleHalfDay utilities
tamaradement 6d2a286
Add tests for new calendar utils
tamaradement 7f0358c
Refactors a comment
tamaradement eacf7b8
Valdiate loc in calendar utils
tamaradement 48f24f3
Removing unused enum
tamaradement f1ceb0e
Document Clockify time-range behavior
tamaradement 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package core | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "google.golang.org/api/calendar/v3" | ||
| ) | ||
|
|
||
| func handleAllDay(startUTC time.Time, | ||
| endUTC time.Time, | ||
| loc *time.Location) (time.Time, time.Time, error) { | ||
|
|
||
| if loc == nil { | ||
| return time.Time{}, time.Time{}, | ||
| fmt.Errorf("location is required") | ||
| } | ||
| // Normalize to local dates | ||
| startLocal := startUTC.In(loc) | ||
| endLocal := endUTC.In(loc) | ||
|
|
||
| y1, m1, d1 := startLocal.Date() | ||
| y2, m2, d2 := endLocal.Date() | ||
|
|
||
| // All-day local time window used for Events.List (TimeMin / TimeMax). | ||
| allDayStart := time.Date(y1, m1, d1, 0, 0, 0, 0, loc) | ||
| // Clockify is inclusive; GCal all-day is [start, end) exclusive. | ||
| // So cover the last OOO day by adding +1 local day to the end date. | ||
| allDayEndExclusive := time.Date(y2, m2, d2, 0, 0, 0, 0, loc).AddDate(0, 0, 1) | ||
|
|
||
| return allDayStart, allDayEndExclusive, nil | ||
| } | ||
|
|
||
| func handleHalfDay( | ||
| halfDayHours *ClockifyTimePeriod, | ||
| loc *time.Location, | ||
| ) (time.Time, time.Time, error) { | ||
| if loc == nil { | ||
| return time.Time{}, time.Time{}, | ||
| fmt.Errorf("location is required") | ||
| } | ||
|
|
||
| if halfDayHours == nil { | ||
| return time.Time{}, time.Time{}, | ||
| fmt.Errorf("half-day request is missing halfDayHours") | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify that loc is not null here. |
||
| startUTC, err := ParseTimeAny(halfDayHours.Start) | ||
| if err != nil { | ||
| return time.Time{}, time.Time{}, | ||
| fmt.Errorf("bad halfDayHours.start: %w", err) | ||
| } | ||
|
|
||
| endUTC, err := ParseTimeAny(halfDayHours.End) | ||
| if err != nil { | ||
| return time.Time{}, time.Time{}, | ||
| fmt.Errorf("bad halfDayHours.end: %w", err) | ||
| } | ||
|
|
||
| startLocal := startUTC.In(loc) | ||
| endLocal := endUTC.In(loc) | ||
|
|
||
| if !endLocal.After(startLocal) { | ||
| return time.Time{}, time.Time{}, | ||
| fmt.Errorf("half-day end must be after start") | ||
| } | ||
|
|
||
| return startLocal, endLocal, nil | ||
| } | ||
|
|
||
| func calendarEventTimeValue(eventTime *calendar.EventDateTime) string { | ||
| if eventTime == nil { | ||
| return "" | ||
| } | ||
|
|
||
| if eventTime.DateTime != "" { | ||
| return eventTime.DateTime | ||
| } | ||
|
|
||
| return eventTime.Date | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify that loc is not null here. (It shouldn't be with the way it's currently called, but just for future-proofing.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I added a
nilcheck forlocto both calendar helpers and added test coverage. I initially thought the caller’s validation was enough, but agree that validating within the helpers makes them safer for any future call sites.