time.Duration support for Days, Months, Years?

1,971 views
Skip to first unread message

a...@google.com

unread,
Jul 1, 2015, 5:05:02 PM7/1/15
to golan...@googlegroups.com
I've got users who want to use a command line flag of "30d" meaning 30 days in the future (or past).

time.Duration is perfect, it supports Nanoseconds, Microseconds, Milliseconds, Seconds, Minutes, Hours
except it doesn't support the longer durations such as Days.

Any discussion about leap seconds, or leap years is orthogonal because it could happen across any Hour boundary as well.



Rob Pike

unread,
Jul 1, 2015, 5:17:00 PM7/1/15
to a...@google.com, golan...@googlegroups.com
When people ask for an hour's delay, it's clear what they mean. (The leap second is irrelevant at that scale.)

But when people ask for a day, the daylight saving time jumps are significant. Do they mean, until this time tomorrow, or do they mean 24 hours? That ambiguity has made us reluctant to define 'day' in the library.

-rob


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh Bleecher Snyder

unread,
Jul 1, 2015, 5:17:05 PM7/1/15
to a...@google.com, golang-nuts
This was recently discussed in issue 11473. Setting aside for a moment
that discussion, as a practical matter, you could write your own
support for it. The flag package supports such things; see
http://golang.org/pkg/flag/#Value. I imagine that others would find it
helpful as a third party library.

-josh

Fatih Arslan

unread,
Jul 1, 2015, 5:40:17 PM7/1/15
to Josh Bleecher Snyder, a...@google.com, golang-nuts
On Thu, Jul 2, 2015 at 12:16 AM, Josh Bleecher Snyder
<josh...@gmail.com> wrote:
> The flag package supports such things; see
> http://golang.org/pkg/flag/#Value. I imagine that others would find it
> helpful as a third party library.

I agree. I really like the Value interface, but not many uses it. Here
is an example for string slice and int slice which I'm using. You can
use it as a foundation to implement a custom flag for yourself:
https://github.com/fatih/flags#flagvalue-implementations-stringslice-and-intslice
Reply all
Reply to author
Forward
0 new messages