github.com/go-chrono/chrono@v0.0.0-20240102183611-532f0d0d7c34/example_offset_time_test.go (about) 1 package chrono_test 2 3 import ( 4 "fmt" 5 6 "github.com/go-chrono/chrono" 7 ) 8 9 func ExampleOffsetTimeOf() { 10 t := chrono.OffsetTimeOf(12, 30, 15, 0, 2, 0) 11 12 fmt.Println(t) 13 // Output: 12:30:15+02:00 14 } 15 16 func ExampleOffsetTime_BusinessHour() { 17 t := chrono.OffsetTimeOf(24, 15, 0, 0, 2, 0) 18 19 fmt.Println(t.BusinessHour()) 20 // Output: 24 21 } 22 23 func ExampleOffsetTime_Sub() { 24 t1 := chrono.OffsetTimeOf(12, 30, 0, 0, 1, 0) 25 t2 := chrono.OffsetTimeOf(12, 15, 0, 0, 2, 0) 26 27 fmt.Println(t1.Sub(t2)) 28 // Output: PT1H15M 29 } 30 31 func ExampleOffsetTime_Add() { 32 t := chrono.OffsetTimeOf(12, 30, 0, 0, 2, 0) 33 34 fmt.Println(t.Add(4 * chrono.Hour)) 35 // Output: 16:30:00+02:00 36 } 37 38 func ExampleOffsetTime_Compare() { 39 t1 := chrono.OffsetTimeOf(12, 30, 0, 0, 1, 0) 40 t2 := chrono.OffsetTimeOf(12, 30, 0, 0, 2, 0) 41 42 if t2.Compare(t1) == -1 { 43 fmt.Println(t2, "is before", t1) 44 } 45 // Output: 12:30:00+02:00 is before 12:30:00+01:00 46 } 47 48 func ExampleOffsetTime_Format() { 49 t := chrono.OffsetTimeOf(12, 30, 15, 0, 2, 30) 50 51 fmt.Println(t.Format(chrono.ISO8601TimeExtended)) 52 // Output: T12:30:15+02:30 53 } 54 55 func ExampleOffsetTime_Parse() { 56 var t chrono.OffsetTime 57 t.Parse(chrono.ISO8601TimeExtended, "T12:30:15+02:30") 58 59 fmt.Println(t) 60 // Output: 12:30:15+02:30 61 }