aboutsummaryrefslogtreecommitdiff
path: root/lib/time
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-07-30lib/time: add missing Hourly section in the package documentationShulhan
2024-12-29all: merge package "lib/ints" and "lib/ints64" into "slices"Shulhan
Now that Go has type parameter, we can use it to use the same function that accept different types for working with slice of int, int64.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-17lib/time: un-export the variable NowShulhan
The original idea of providing Now is to mock the current time in testing Scheduler. Since this variable can be overridden by other packages, it is not safe to export it, hence we un-export it here so it can be used internal only.
2023-12-17lib/time: remove UnixMicro and UnixMilliShulhan
Both of those methods has been added into standard library as [Time.UnixMicro] and [Time.UnixMilli] since Go 1.17.
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-09-11lib/time: add missing comment to exported error, variables, and constansShulhan
While at it, realign struct in TestScheduler_minutely from 48 to 40 bytes.
2023-05-02lib/time: calculate the next event on Scheduler runShulhan
This allow user to call the Next method, to know the next time the scheduler will be triggered, after receiving the event.
2023-04-09lib/time: replace lib/io#Reader with lib/bytes#ParserShulhan
The lib/io#Reader will be deprecated and replaced with lib/bytes#Parser in the future.
2023-02-25lib/time: changes the Scheduler nextSeconds to time.DurationShulhan
Using time.Duration give better ticker precision, minimize panic due to checking for <= 0 value for Reset.
2023-02-25lib/time: add unit tests for the rest of SchedulerShulhan
We found dead code in parseListTimeOfDay and way to simplify getting default minute in nextHourly.
2023-02-25lib/time: group each schedule by section on NewSchedulerShulhan
This is for better readibility on the comment section.
2023-02-25lib/time: fix After and Before logicShulhan
Due to copy, paste and lack of testing, some condition should be check using < instead of >. While at it, add other examples for full test coverage.
2023-02-25lib/time: split the Scheduler parser to simplify testingShulhan
Previously, testing NewScheduler cause a new goroutine run for each call and this is slow. To simplify it, we split the parser and create internal newScheduler that accept the schedule and current time.
2023-02-25lib/time: simplify the Scheduler run logicShulhan
Previously, we calculate the ticker to every 60 seconds or less. This require additional computation on how many seconds left after the previous tick and sometimes cause panic if the nextSeconds is zero. In this changes, we use the nextSeconds directly as duration of ticker.
2023-02-25lib/time: add method Next to SchedulerShulhan
The Next method return the next schedule. This changes require refactoring on each calculation on schedule by returning the next time.Time instead of setting it inside directly, which affect on simplification of nextMinutely and nextHourly.
2023-02-22lib/time: implement SchedulerShulhan
Scheduler is a timer that run periodically based on calendar or day time. A schedule is divided into monthly, weekly, daily, hourly, and minutely. An empty schedule is equal to minutely, a schedule that run every minute.
2023-02-22lib/time: add new type ClockShulhan
Clock represent 24 hours time with hour, minute, and second. An hour value is from 0 to 23, a minute value is from 0 to 59, and a second value is from 0 to 59.
2023-02-22lib/time: add global variable Now as functionShulhan
The Now variable return the current local time. Unlike standard library, this is a variable that can be override to mock the current time during testing.
2022-09-13lib/test: change the Assert parameter to WriterShulhan
Since we only need to call Log and Fatalf during Assert, no need to pass the whole instance of testing.T to Assert. By changing it to Writer, we also can test the Assert. This remove the AssertBench, because it have the same function parameters and body as Assert.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2021-02-03time: add function UnixMicro that return UNIX time in micro secondsShulhan
While at it, replace the unit tests with an example so we can both do unit testing and provide an examples in documentation.
2020-06-06all: use default linter optionsShulhan
2020-05-07time: fix test with latest GoShulhan
2020-02-28time: add functions to get Unix time in milliseconds (int64 and string)Shulhan
2020-01-20time: change the Microsecond return type from int to int64Shulhan
2019-06-14ascii: new library for working with ASCII charactersShulhan
This library previously part of bytes package. To make it bytes package consistent (only working with slice of byte), we move all ASCII related constants, variables, and functions into new package.
2019-06-14all: fix nolint formatShulhan
The valid syntax to suppress linter warnings is "//nolint:<name>" with no space between comment and "nolint" and between ":". Also, we move the placement of nolint directive to the top of statements for multiple nolint in the same scope. While at it, fix and supress some linter warnings.
2019-03-01all: fix warnings from linterShulhan
Most of the warnings caused by update to linter which cause global variables declared with grouping "( ... )" and that has been suppressed, are become false-positive again.
2019-02-28time: add function to get micro secondsShulhan
Micro seconds is the first six digits after seconds in output of UnixNano().
2019-02-05lib/io: rename Reader SkipSpace to SkipSpacesShulhan
2019-02-05lib/time: suppress linter warnings on known global variablesShulhan
2019-02-05lib/time: update affected by refactoring on lib/io.ReaderShulhan
Also, add more unit tests for false positive and simplify code.
2019-02-05lib/email: new package for working with Internet Message FormatShulhan
This package provide library for parsing email message format as specified in RFC 5322.
2019-01-29lib/time: uncapitalized the first letter of error messageShulhan
2018-11-29all: fix warnings from lintersShulhan
2018-11-29all: fixes warning from lintersShulhan
2018-11-29all: fix warning from lintersShulhan
2018-09-03Move all byte(s) related constant and functions from package text to bytesShulhan
2018-09-01Rename "lib/file" to "lib/io"Shulhan
2018-09-01Add package time with Day and Week as durationShulhan