Skip to content

Generate a slice representing a given duration. Each slice index would represent a different unit of time.

Notifications You must be signed in to change notification settings

kroikie/durationslice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Duration Slice Build Status

Duration Slice is a Go library that generates a slice representation of a duration in units specified.

The builtin Duration provides the ability to retrieve a duration in different units eg: hours, minutes, seconds etc. However partial representations are not available, Duration Slice provides this partial representation.

If you had a Duration of 120 seconds and wanted to represent it in minutes and seconds you would have to do the arithmetic yourself. With Duration Slice you can provide the duration and a string representing what units you want the duration divided into and it will return a slice with the corresponding unit values.

Example

If you had a duration that was 75 minutes and 65 seconds long and you wanted to represent that as hours, minutes and seconds. You could use the following:

ds, err := durationslice.Process(time.Duration((75*time.Minute)+(65*time.Second)), "h m s")
if err != nil {
    print(err.Error())
	return
}
fmt.Printf("%@", ds)

output: [1 16 5]

The resulting slice would give the values corresponding to the units specified in the unit string.

About

Generate a slice representing a given duration. Each slice index would represent a different unit of time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages