Skip to content
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

fix: massively improve durationRound function, add support for durations #364

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
docs: update documentation on 'durationRound'
FlorianLoch committed Mar 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d39aaa25309a63aff2559349f380ff7743f353c5
19 changes: 12 additions & 7 deletions docs/date.md
Original file line number Diff line number Diff line change
@@ -51,27 +51,32 @@ dateInZone "2006-01-02" (now) "UTC"

Formats a given amount of seconds as a `time.Duration`.

This returns 1m35s

```
duration "95"

# Yields 1m35s
```

## durationRound

Rounds a given duration to the most significant unit. Strings and `time.Duration`
gets parsed as a duration, while a `time.Time` is calculated as the duration since.
Rounds a given duration to the most significant unit.
It always round down, e.g. `durationRound "2h10m5s"` yields `2h` - making it more a `floor` than a `round`.

This return 2h
`durationRound` accepts `time.Duration` as input; `string` gets parsed into `time.Duration`, `int`, `int64` and
`float64` are read as durations in seconds.
When `time.Time` is given the difference between `time.Now()` and the given time is used as duration.


```
durationRound "2h10m5s"
```

This returns 3mo
# Yields 2h
```

```
durationRound "2400h10m5s"

# Yields 3mo
```

## unixEpoch