Sebastien Binet
unread,Sep 4, 2012, 8:48:22 AM9/4/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
hi there,
migrating a python-based application to a golang-based one, I had to
handle parsing duration like the one in the title (ie: support for
'week' as a quantum of duration).
the python version was shelling-out to call
os.popen('date -d "%(duration)s" +%%Y-%%m-%%d' % dct)
yeah... nice.
but I actually had to do the same thing b/c of the lack of support for
"-1week".
looking at the code, it would seem rather straightforward to add to the
unitMap:
var unitMap = map[string]float64{
"ns": float64(Nanosecond),
"us": float64(Microsecond),
"µs": float64(Microsecond), // U+00B5 = micro symbol
"μs": float64(Microsecond), // U+03BC = Greek letter mu
"ms": float64(Millisecond),
"s": float64(Second),
"m": float64(Minute),
"h": float64(Hour),
+ "day": float64(Day),
+ "week": float64(Week),
}
where the following consts would be added:
const (
Nanosecond Duration = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
Minute = 60 * Second
Hour = 60 * Minute
+ Day = 24 * Hour
+ Week = 7 * Day
)
(actually, should this be 24*Hour or
23*Hour + 56*Minute + 4*Second +91*Millisecond?
ie: a sidereal day ?)
before sending a CL, I wanted to test the waters...
-s