@plandek-utils/time-utils
TypeDoc generated docs in here
Github repo here
small utils for managing Time. It is intended to be used in tests.
Installation
yarn add @plandek-utils/time-utils
or npm install @plandek-utils/time-utils
.
Dependencies
it requires timekeeper
V2 Drops dayjs support
In v1.x dayjs objects were supported. This ended up being problematic because of issues with dayjs versions. It also added a dependency that is not strictly needed. That's why from v2.x on dayjs is no longer supported and it is removed as a dependency.
Usage
we get 2 functions:
freezeTime(time, fn)
: freezes time to the given one, executes the given function, and resets the time before returning the result of that execution.freezeTimeAwait(time, asyncFn)
: same as freezeTime()
but expects an async function, and it waits for its return before resetting the time
function renderTime() {
const d = new Date()
console.log(d.toISOString())
}
renderTime()
const time = new Date("2018-01-02T13:14:15.123Z")
const res = freezeTime(time, () => { renderTime(); return 'blah' })
console.log(res)
renderTime()
Development, Commits, versioning and publishing
See documentation for development
See The Typescript-Starter docs.
Commits and CHANGELOG
For commits, you should use commitizen
yarn global add commitizen
git cz
As typescript-starter docs state:
This project is tooled for conventional changelog to make managing releases easier. See the standard-version documentation for more information on the workflow, or CHANGELOG.md
for an example.
yarn run version
You may find a tool like wip
helpful for managing work in progress before you're ready to create a meaningful commit.
Creating the first version
Once you are ready to create the first version, run the following (note that reset
is destructive and will remove all files not in the git repo from the directory).
yarn run reset && yarn run test && yarn run doc:html
yarn run version -- --first-release
And after that, remember to publish the docs.
And finally push the new tags to github and publish the package to npm.
git push --follow-tags origin master
yarn publish --access public
Publish the Docs
yarn run doc:html && yarn run doc:publish
This will generate the docs and publish them in github pages.
Generate a version
There is a single yarn command for preparing a new release. See One-step publish preparation script in TypeScript-Starter
yarn prepare-release
git push --follow-tags origin master
yarn publish --access public