Class GolangDuration
java.lang.Object
com.couchbase.analytics.client.java.internal.utils.time.GolangDuration
Helper methods that have to do with certain golang-specific format the server uses.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringencodeDurationToMs(Duration duration) Encodes a Java duration into the encoded golang format.static DurationparseDuration(String duration) Parses a Go duration string using the same rules as Go's time.ParseDuration method.
-
Method Details
-
encodeDurationToMs
Encodes a Java duration into the encoded golang format.- Parameters:
duration- the duration to encode.- Returns:
- the encoded duration.
-
parseDuration
Parses a Go duration string using the same rules as Go's time.ParseDuration method.A Go duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". The unit suffix may be omitted if the duration is "0".
The internal representation is a signed long number of nanoseconds. This means the longest possible duration is approximately 290 years.
- Throws:
IllegalArgumentException- if the input does not match the Go duration string syntax or if it describes a duration longer than 2^63−1 nanoseconds.
-