- Notifications
You must be signed in to change notification settings - Fork0
Duration string parser for GO
License
NotificationsYou must be signed in to change notification settings
boolproof/p6y
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Package provides parsing of duration information encoded in string compliant with format described byISO 8601 (https://en.wikipedia.org/wiki/ISO_8601#Durations).
OnlyPnYnMnDTnHnMnS
andPnW
formats are parsed by the package (no suppport for bothPYYYYMMDDThhmmss
andP[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]
).
Package can not parse values with fractions (only integer values).
If parsing is successfull (no error), use following result struct methods to access intrger values of duration components:
Years()
Months()
Days()
Weeks()
Hours()
Minutes()
Seconds()
package mainimport ("fmt""github.com/boolproof/p6y")funcmain() {d,err:=p6y.NewDuration("P7Y5DT12H")iferr==nil {fmt.Printf("This will take %d years, %d months,"+"%d days and %d hours\n",d.Years(),d.Months(),d.Days(),d.Hours())//outputs: "This will take 7 years, 0 months, 5 days and 12 hours"}else {fmt.Println(err.Error())}}
About
Duration string parser for GO
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.