{"id":13491279,"url":"https://github.com/hyperjumptech/jiffy","last_synced_at":"2025-05-14T15:30:39.323Z","repository":{"id":43120254,"uuid":"267555267","full_name":"hyperjumptech/jiffy","owner":"hyperjumptech","description":"A very useful Golang library used for working with describing time.Duration.","archived":false,"fork":false,"pushed_at":"2022-09-15T01:13:55.000Z","size":27,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T20:05:58.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperjumptech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-2.0.txt","code_of_conduct":"CODE_OF_CONDUCTS.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-28T10:02:24.000Z","updated_at":"2025-01-16T05:42:58.000Z","dependencies_parsed_at":"2022-08-26T17:52:22.284Z","dependency_job_id":null,"html_url":"https://github.com/hyperjumptech/jiffy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fjiffy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fjiffy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fjiffy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Fjiffy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperjumptech","download_url":"https://codeload.github.com/hyperjumptech/jiffy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254171543,"owners_count":22026459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:00:55.183Z","updated_at":"2025-05-14T15:30:38.621Z","avatar_url":"https://github.com/hyperjumptech.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Jiffy\r\n\r\n[![Build Status](https://travis-ci.org/hyperjumptech/jiffy.svg?branch=master)](https://travis-ci.org/hyperjumptech/jiffy)\r\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\r\n\r\nJiffy is a golang library to work with `time.Duration`.\r\nIt provides a simpler way on defining and describing `time.Duration`.\r\n\r\n*Jiffy* extends the `func (d Duration) String() string` where Jiffy can describe a duration up to day, month even year. Verbose or non-verbose\u003cbr\u003e\r\n*Jiffy* also extends the `func ParseDuration(s string) (Duration, error)` where Jiffy can parse day, month and year element in a more flexible formating.\r\n\r\nUsecases :\r\n\r\n* You have measured a processing time duration and want to display it in a format easily understand by human.\r\n\r\n```go\r\nstartTime := time.Now()\r\n/*\r\n    you do a heavy time consuming process here\r\n*/\r\nendTime := time.Now()\r\nduration := startTime.Sub(endTime)\r\n\r\n// print using time.Duration.String() function\r\nfmt.Println(duration.String()) \r\n// this print like \"30086h0m0s\", not so easy to understand\r\n\r\n// print using jiffy\r\nfmt.Println(jiffy.DescribeDuration(duration, jiffy.NewWant()))\r\n// this print \"3y 4mon 13d 14h\"\r\n```\r\n\r\n* You want to provide a simple way for your user to define some time duration.\r\n\r\n```go\r\nworkTime := getUserInput() // user key in his working time as string. eg. \"3h 15minutes\" or \"3 hours 15 minutes\" or \"3h and 15m\"\r\nworkDuration, err := jiffy.DurationOf(workTime)\r\nif err != nil {\r\n    panic(err)\r\n}\r\nif workDuration \u003e 2 * time.Hour {\r\n    // do something.\r\n}\r\n```\r\n\r\nToo add *Jiffy* into your project.\r\n\r\n```\r\n$ go get github.com/hyperjumptech/jiffy\r\n```\r\n\r\nTo import *Jiffy* in your coode\r\n\r\n```go\r\nimport \"gitlab.com/hyperjujptech/jiffy\"\r\n```\r\n\r\n## Creating time.Duration from a Description\r\n\r\n```go\r\ndur, err := jiffy.DurationOf(\"2 hours 30 minutes\")\r\nif err != nil {\r\n    panic(err)\r\n}\r\n```\r\n\r\nExamples of duration descriptions\r\n\r\n* `5d 3h 12m`\r\n* `2y 3mon 15d`\r\n* `12 days 16hours`\r\n* `1minute 15seconds`\r\n* `4seconds and 15milliseconds`\r\n* `25s123ms59microsecond`\r\n\r\n### Time units\r\n\r\n| Unit        | Notation | Example(s) |\r\n| ----------- | -------- | ---------- |\r\n| Year        | `y` or `year` or `years` | `25y` or `25 y` or `25 years` |\r\n| Month       | `mon` or `month` or `months` | `2.5mon` or `3 month` or `6 months` |\r\n| Day         | `d` or `day` or `days` | `0.5d` or `1.5day` or `2 days` |\r\n| Hour        | `h` or `hrs` or `hour` or `hours` | `1h` or `2hour` or `3 hours` |\r\n| Minute      | `m` or `min` or `minute` or `minutes` | `4m` or `5minute` or `6minutes`  |\r\n| Second      | `s` or `sec` or `second` or `seconds` | `7s` or `8 second` or `9seconds` |\r\n| Millisecond | `ms` or `millisecond` or `milliseconds` | `120ms` or `450 millisecond` or `500 milliseconds` |\r\n| Microsecond | `us` or `microsecond` or `microseconds` | `300us` or `1200.5microsecond` or `0.1 microseconds` |\r\n\r\n_Note_ :\r\n\r\n* You can add the word `and` between time unit. For example : `12h and 30m`\r\n* Your duration description is *case insensitive*\r\n* You could always use *real* literals. For example : `12.5 days`\r\n* You also can use a negative sign. For example : `-5d`\r\n* Whitespaces (eg. tabs or space) is ignored, so you can always add as many spaces or tabs as you want.\r\n* `CR` or `LF` is an illegal character.\r\n* When you specify each unit, it can be in any order. For example `12 days 5 hour 3sec` is the same as `3 second 5hours 12day`\r\n* You can repeat same time units. For example : `5d 5d 1d` equals to `11d`\r\n\r\n## Describing a time.Duration\r\n\r\nTo have a `time.Duration` get described, you can use \r\n\r\n```go\r\nfunc jiffy.DescribeDuration(dur time.Duration, want *jiffy.Want) string\r\n```\r\n\r\n`jiffy.Want` is a _struct_ to specify what time unit should be displayed to describe the `time.Duration`.\r\nBecause, a duration of `3 hours` can also be described in `180 minutes` or `10800 seconds`. \r\n\r\nFollowing is the `jiffy.Want` _struct_\r\n\r\n```go\r\ntype Want struct {\r\n\tYear        bool   // set this true if you want year to be calcuated and displayed.\r\n\tMonth       bool   // or this one for month\r\n\tDay         bool   // or this one for day\r\n\tHour        bool   // or this one for hour\r\n\tMinute      bool   // or this one for minute\r\n\tSecond      bool   // or this one for second\r\n\tMillisecond bool   // or this one for millisecond\r\n\tMicrosecond bool   // or this one for microsecond\r\n\tSeparator   string // specify this string as separator between time units\r\n\tVerbose     bool   // verbose/nonverbose mode\r\n}\r\n```\r\n\r\n`Want` also have a default _constructor_ function \r\n\r\n```go\r\nfunc NewWant() *Want {\r\n\treturn \u0026Want{\r\n\t\tYear:      true,\r\n\t\tMonth:     true,\r\n\t\tDay:       true,\r\n\t\tHour:      true,\r\n\t\tMinute:    true,\r\n\t\tSecond:    true,\r\n\t\tVerbose:   false,\r\n\t\tSeparator: \" \",\r\n\t}\r\n}\r\n```\r\n\r\n### Verbosity\r\n\r\nIf you want to describe a `time.Duration` verbosely the `DescribeDuration` function will return for example\r\n\r\n```\r\n1 hour 2 minutes 4 seconds\r\n```\r\n\r\nAnd if you set the `Want.Verbose = false` it will produce\r\n\r\n```\r\n1h 2m 4s\r\n```\r\n\r\n### Describe example\r\n\r\n```go\r\naDuration := 1 * time.Second + 1 * time.Minute + 1 * time.Hour\r\n\r\nfmt.Println( jiffy.DescribeDuration(aDuration, \u0026jiffy.Want{\r\n    Hour: true,\r\n    Minute: true,\r\n    Second: true,\r\n    Verbose: false,\r\n    Separator: \" \",\r\n}) ) // this will print \"1h 1m 1s\"\r\n\r\nfmt.Println( jiffy.DescribeDuration(aDuration, \u0026jiffy.Want{\r\n    Hour: true,\r\n    Minute: true,\r\n    Second: true,\r\n    Verbose: true,\r\n    Separator: \" \",\r\n}) ) // this will print \"1 hour 1 minute 1 second\"\r\n\r\nfmt.Println( jiffy.DescribeDuration(aDuration, \u0026jiffy.Want{\r\n    Minute: true,\r\n    Second: true,\r\n    Verbose: true,\r\n    Separator: \", \",\r\n}) ) // this will print \"61 minutes, 1 seconds\"\r\n\r\nfmt.Println( jiffy.DescribeDuration(aDuration, \u0026jiffy.Want{\r\n    Second: true,\r\n    Verbose: true,\r\n    Separator: \", \",\r\n}) ) // this will print \"3661 seconds\"\r\n```\r\n\r\n## FAQ\r\n\r\n*Q* : Why *jiffy* does not support *Nanosecond* ?\u003cbr\u003e\r\n*A* : Nanosecond is too much. No human can comprehend that. Or if you want it so badly,  please submit a PR.\r\n\r\n*Q* : Why *jiffy* ? Not the golang's `func (d Duration) String() string` and `func ParseDuration(s string) (Duration, error)` ?\u003cbr\u003e\r\n*A* : Because *jiffy* parsing and producing up to  year, month, date, and it parses string in more flexible way\r\n\r\n# Tasks and Help Wanted.\r\n\r\nYes. We need contributor to make **Jiffy** even better and useful to Open Source Community.\r\n\r\nIf you really want to help us, simply `Fork` the project and apply for Pull Request.\r\nPlease read our [Contribution Manual](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCTS.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Fjiffy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperjumptech%2Fjiffy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Fjiffy/lists"}