Repository navigation
feat(time): work out the time report from my worklogs - #149
Merged
Merged
Conversation
The time service's report package: the hours logged on each of the last 7 days, the weekdays before today with nothing logged, and this week's hours against the 40-hour target. Days follow the zone of the time given, and start as the clocks skip midnight where they do (decision 181).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Brief
Goal. The
timeservice's report, worked out from my worklogs: the hours I logged on each of the last 7 days, the weekdays among them with nothing logged, and this week's hours against the 40-hour target. It's a pure package,services/time/internal/report, for the service that the next step brings. The third oftime-tracking's twelve steps (decision 181).Scope.
services/time/internal/report/report.go:Report(Days,Week),Day(Date,LoggedHours,Missing) andWeek(LoggedHours,TargetHours);Span(now): the span of time that the report atnowcovers;New(worklogs, now): the report atnowof the worklogs.docs/plan.md: decision 181 (the split, twelve steps, the report's rules), §0 row, §8.2 the new step marked done andtime-servicereworded.Out of scope.
GET /time/report(time-service).Acceptance criteria.
Span(now)returns the start of the day six days beforenow's, and the start of the day afternow's, innow's location. In a zone whose clocks skip midnight, a day starts as they skip it (America/Havana's 01:00), not in the day before.Newlists the 7 days that end withnow's, the earliest first. Each has:2006-01-02;now's location.A worklog that crosses midnight counts wholly on the day it starts. A worklog of another day is left out.
A day is missing when it's Monday to Friday, before today, with nothing logged. Today, Saturdays and Sundays never are, and nor is a day with any time logged.
The week's logged hours add up the days from this week's Monday through today; the days before Monday don't count. Its target is 40 hours.
Hours are the time logged in hours, as a number (1 h 30 m is 1.5). Sums add up durations before they turn into hours.
The JSON is
{"days":[{"date","loggedHours","missing"}…],"week":{"loggedHours","targetHours"}}, withdaysalways an array of 7.Nothing reads the clock or the local zone:
nowbrings both.mise run checkpasses.What changed
services/time/internal/report/report.go(new), thetimeservice's first package:Report,DayandWeek, as in the brief;Span(now)andNew(worklogs, now);dateOf,dayStart,mondayOfandweekday.Days are counted on civil dates at midnight UTC, where no clock changes.
dayStartusestime.Date's midnight, unless that falls on the day before. In that case it takes the end of the zone then in effect, which is the moment the clocks skip midnight. Durations are added up first and turned into hours once.span_test.go(new):Spanin Budapest across both clock changes, at midnight, a nanosecond before midnight, in UTC, and in the four zones whose clocks skip midnight in 2026: Havana, Santiago, Beirut and Cairo.report_test.go(new) covers:+05:30start, today, and tomorrow left out;now's zone;docs/plan.md:time-reportmarked done, andtime-serviceandtime-pagereworded to say "time report".QA
Every acceptance criterion has a test. A grep finds no
time.Now,time.Local,.Local(),time.Sinceortime.Untilin the package (AC7).Zones: a brute-force probe went through every zone in macOS's tzdata 2025c, every day from 2026 to 2030. It found 40 days that don't start at midnight:
time.Dateputs midnight on the day before (Havana, Santiago, Azores, and their aliases), anddayStart's fix gives the day's real start;time.Datealready gives 01:00, the moment the clocks skip.None of these days is the first of a month, and every gap is one hour.
Mutations: 47 of 47 caught (
go test ./services/time/...). They cover the span's bounds and zone, the skipped-midnight fix, the days' zone, the clock, the number of days, the date's layout, hours, sums, each rule for missing days, the week's Monday, the target and every JSON name. The first run left five survivors, and QA added tests for them:TZ=UTC, as on CI. The tests pass with the machine in UTC, Havana, Kiritimati, Kolkata and Niue.One mutant first failed to build (
mondayunused) and was rewritten. Two mutants were left out because they behave the same on every day from 2026 to 2030:<for!=in the fix (no skipped midnight falls on a month's first day), and adding an hour forZoneBounds(every gap is one hour).Coverage of the package: 100%.
Review
No blocking findings. Non-blocking:
weekdayreturns whether a date is Monday to Friday. Its name is close totime.Weekday, but it reads well where it's used.time-service: the pod'stime.Localis UTC unlessTZis set and the image has tzdata. Check both there, and inhomelab-time.Gates
mise run --jobs 1 checkpassed locally:-race, Go coverage 95.9% total;tsc, knip,pnpm audit;SonarQube Cloud runs on demand (decision 132).
Merged under the user's standing OK (2026-10-26): merge once CI's
checkis green, and review everything at the end.