Documentation
¶
Overview ¶
Package humanize is parses some limited time and byte sizes data to human readable formats.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Binary ¶
Binary formats the bytes integer to localized, readable string using binary units of measure.
Example ¶
package main import ( "fmt" "github.com/bengarrett/sauce/humanize" "golang.org/x/text/language" ) func main() { const size = int64(15724) us, de := language.AmericanEnglish, language.German fmt.Printf("Filesize is %s.\n", humanize.Binary(size, us)) fmt.Printf("Dateigröße ist %s.", humanize.Binary(size, de)) }
Output: Filesize is 15.4 KiB. Dateigröße ist 15,4 KiB.
func Decimal ¶
Decimal formats the bytes integer to localized readable string using decimal units of measure.
Example ¶
package main import ( "fmt" "github.com/bengarrett/sauce/humanize" "golang.org/x/text/language" ) func main() { const size = int64(15724) us, de := language.AmericanEnglish, language.German fmt.Printf("Filesize is %s.\n", humanize.Decimal(size, us)) fmt.Printf("Dateigröße ist %s.", humanize.Decimal(size, de)) }
Output: Filesize is 15.7 kB. Dateigröße ist 15,7 kB.
Types ¶
type Layout ¶
type Layout string
Layout is a predefined time format.
const ( DMY Layout = "2 Jan 2006" // day month year YMD Layout = "2006 Jan 2" // year month day MDY Layout = "Jan 2 2006" // month day year H12 Layout = "3:04 pm" // 12 hour clock H24 Layout = "15:04" // 24 hour clock )
Date and time layouts.
const ( DMY12 Layout = DMY + " " + H12 // 2 Jan 2006 3:04 pm DMY24 Layout = DMY + " " + H24 // 2 Jan 2006 15:04 YMD12 Layout = YMD + " " + H12 // 2006 Jan 2 3:04 pm YMD24 Layout = YMD + " " + H24 // 2006 Jan 2 15:04 MDY12 Layout = MDY + " " + H12 // Jan 2 2006 3:04 pm MDY24 Layout = MDY + " " + H24 // Jan 2 2006 15:04 )
Date with time layouts.
func (Layout) Format ¶
Format returns the time using the predefined layout.
Example ¶
package main import ( "fmt" "time" "github.com/bengarrett/sauce/humanize" ) func main() { t := time.Date(2020, 1, 1, 12, 0, 0, 0, time.UTC) fmt.Println(humanize.DMY.Format(t)) fmt.Println(humanize.YMD24.Format(t)) }
Output: 1 Jan 2020 2020 Jan 1 12:00
Click to show internal directories.
Click to hide internal directories.