github.com/go-chrono/chrono@v0.0.0-20240102183611-532f0d0d7c34/example_local_date_test.go (about) 1 package chrono_test 2 3 import ( 4 "fmt" 5 6 "github.com/go-chrono/chrono" 7 ) 8 9 func ExampleLocalDateOf() { 10 d := chrono.LocalDateOf(2007, chrono.May, 20) 11 12 fmt.Println(d) 13 // Output: 2007-05-20 14 } 15 16 func ExampleOfDayOfYear() { 17 d := chrono.OfDayOfYear(2020, 80) 18 19 fmt.Println("The 80th day of 2020 is", d) 20 // Output: The 80th day of 2020 is 2020-03-20 21 } 22 23 func ExampleOfFirstWeekday() { 24 d := chrono.OfFirstWeekday(2020, chrono.July, chrono.Friday) 25 26 fmt.Println("The first Friday of July 2020 is", d) 27 // Output: The first Friday of July 2020 is 2020-07-03 28 } 29 30 func ExampleLocalDate_Weekday() { 31 d := chrono.LocalDateOf(2007, chrono.May, 20) 32 33 fmt.Println(d.Weekday()) 34 // Output: Sunday 35 } 36 37 func ExampleLocalDate_compare() { 38 d1 := chrono.LocalDateOf(2007, chrono.May, 20) 39 d2 := chrono.LocalDateOf(2009, chrono.June, 5) 40 41 if d2 > d1 { 42 fmt.Println(d2, "is after", d1) 43 } 44 // Output: 2009-06-05 is after 2007-05-20 45 } 46 47 func ExampleLocalDate_difference() { 48 d1 := chrono.LocalDateOf(2007, chrono.May, 20) 49 d2 := chrono.LocalDateOf(2007, chrono.May, 25) 50 51 fmt.Printf("There are %d days from %s to %s\n", d2-d1, d1, d2) 52 // Output: There are 5 days from 2007-05-20 to 2007-05-25 53 } 54 55 func ExampleLocalDate_add_subtract() { 56 d := chrono.LocalDateOf(2007, chrono.May, 20) 57 58 d += 8 59 d -= 3 60 61 fmt.Println(d) 62 // Output: 2007-05-25 63 } 64 65 func ExampleLocalDate_AddDate() { 66 d := chrono.LocalDateOf(2007, chrono.May, 20) 67 d = d.AddDate(0, 1, 1) 68 69 fmt.Println(d) 70 // Output: 2007-06-21 71 } 72 73 func ExampleLocalDate_Format() { 74 d := chrono.LocalDateOf(2007, chrono.May, 20) 75 76 fmt.Println(d.Format(chrono.ISO8601DateExtended)) 77 // Output: 2007-05-20 78 } 79 80 func ExampleLocalDate_Parse() { 81 var d chrono.LocalDate 82 _ = d.Parse(chrono.ISO8601DateExtended, "2007-05-20") 83 84 fmt.Println(d) 85 // Output: 2007-05-20 86 }