github.com/go-chrono/chrono@v0.0.0-20240102183611-532f0d0d7c34/example_local_time_test.go (about)

     1  package chrono_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/go-chrono/chrono"
     7  )
     8  
     9  func ExampleLocalTimeOf() {
    10  	t := chrono.LocalTimeOf(12, 30, 15, 0)
    11  
    12  	fmt.Println(t)
    13  	// Output: 12:30:15
    14  }
    15  
    16  func ExampleLocalTime_BusinessHour() {
    17  	t := chrono.LocalTimeOf(24, 15, 0, 0)
    18  
    19  	fmt.Println(t.BusinessHour())
    20  	// Output: 24
    21  }
    22  
    23  func ExampleLocalTime_Sub() {
    24  	t1 := chrono.LocalTimeOf(12, 30, 0, 0)
    25  	t2 := chrono.LocalTimeOf(12, 15, 0, 0)
    26  
    27  	fmt.Println(t1.Sub(t2))
    28  	// Output: PT15M
    29  }
    30  
    31  func ExampleLocalTime_Add() {
    32  	t := chrono.LocalTimeOf(12, 30, 0, 0)
    33  
    34  	fmt.Println(t.Add(4 * chrono.Hour))
    35  	// Output: 16:30:00
    36  }
    37  
    38  func ExampleLocalTime_Compare() {
    39  	t1 := chrono.LocalTimeOf(12, 30, 0, 0)
    40  	t2 := chrono.LocalTimeOf(12, 15, 0, 0)
    41  
    42  	if t2.Compare(t1) == -1 {
    43  		fmt.Println(t2, "is before", t1)
    44  	}
    45  	// Output: 12:15:00 is before 12:30:00
    46  }
    47  
    48  func ExampleLocalTime_Format() {
    49  	t := chrono.LocalTimeOf(12, 30, 15, 0)
    50  
    51  	fmt.Println(t.Format(chrono.ISO8601TimeExtended))
    52  	// Output: T12:30:15
    53  }
    54  
    55  func ExampleLocalTime_Parse() {
    56  	var t chrono.LocalTime
    57  	t.Parse(chrono.ISO8601TimeExtended, "T12:30:15")
    58  
    59  	fmt.Println(t)
    60  	// Output: 12:30:15
    61  }