Documentation
¶
Overview ¶
Library that extends time.Duration from standard library with days, months and years.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrCharDotAgain = errors.New("dot character was specified again") ErrCharSignAgain = errors.New("sign character was specified again") ErrInputEmpty = errors.New("input string is empty") ErrNumberUnspecified = errors.New("number was not specified") ErrOnlyInteger = errors.New("years, months and days can only be integer") ErrUnexpectedChar = errors.New("unexpected character was specified") ErrUnexpectedUnit = errors.New("unexpected unit was specified") ErrUnitUnspecified = errors.New("unit was not specified") )
Functions ¶
This section is empty.
Types ¶
type Whilst ¶
Time duration with days, months and years.
func Parse ¶
Parses a string representation of the duration.
A duration string consists of several decimal numbers supplemented with an unit of measurement. There may be spaces between a numbers supplemented with an unit, but there must not be spaces between a number and an unit. One of a signs - or + can be specified at a beginning of a string.
A value of days, months and years can only be an integer and cannot be greater than 65535 for each.
Remaining values must not be greater than 9223372036854775807 for positive duration and 9223372036854775808 for negative duration and may have a fractional part.
List of valid units:
- y - year
- mo - month
- d - day
- h - hour
- m - minute
- s - second
- ms - millisecond
- µs | μs | us - microsecond
- ns - nanosecond
Example of strings:
- 2y3mo10d 24h30m28.02006002s
- - 2y3mo10d24h30m28.02006002s
- + 2y 3mo 10d 24h 30m 28.02006002s
Example ¶
package main
import (
"fmt"
"time"
"github.com/akramarenkov/whilst"
)
func main() {
from := time.Date(2023, time.April, 1, 0, 0, 0, 0, time.UTC)
whl, err := whilst.Parse("2y")
if err != nil {
panic(err)
}
fmt.Println(whl)
fmt.Println(whl.When(from))
fmt.Println(whl.Duration(from))
}
Output: 2y 2025-04-01 00:00:00 +0000 UTC 17544h0m0s
Example (Compound) ¶
package main
import (
"fmt"
"github.com/akramarenkov/whilst"
)
func main() {
whl, err := whilst.Parse("2y 3mo 10d 23.5h 59.5m 58.01003001s 10ms 30µs 10ns")
if err != nil {
panic(err)
}
fmt.Println(whl)
}
Output: 2y3mo10d24h30m28.02006002s
func (Whilst) Duration ¶
Returns a time.Duration representation of the duration.
Time from is necessary because shift by days, months and years is not deterministic and depends on the time relative to which it occurs.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
ascii
Internal package used to work with 7-bit US-ASCII characters.
|
Internal package used to work with 7-bit US-ASCII characters. |
|
consts
Internal package with constants common to this module.
|
Internal package with constants common to this module. |
|
credible
Internal package used for integer calculations with overflow checking.
|
Internal package used for integer calculations with overflow checking. |