0
0
Fork 0
mirror of https://github.com/crazy-max/diun.git synced 2025-01-03 08:08:34 +00:00
crazy-max_diun/vendor/github.com/dromara/carbon/v2/calendar/persian
2024-12-21 00:26:14 +01:00
..
persian.go switch from durafmt to github.com/dromara/carbon 2024-12-21 00:26:14 +01:00
README.cn.md switch from durafmt to github.com/dromara/carbon 2024-12-21 00:26:14 +01:00
README.jp.md switch from durafmt to github.com/dromara/carbon 2024-12-21 00:26:14 +01:00
README.md switch from durafmt to github.com/dromara/carbon 2024-12-21 00:26:14 +01:00

Persian(Jalaali) Calendar

English | 简体中文 | 日本語

Usage and example

Convert Gregorian calendar to Persian calendar
// Get persian year
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
// Get persian month
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
// Get persian day
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
// Get persian hour
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
// Get persian minute
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
// Get persian second
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15

// Get persian date and time string
carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15

// Get persian month as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد

// Get persian short month as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد

// Get persian week as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه

// Get persian short week as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د

Convert Persian calendar to Gregorian calendar
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00
Comparison
// Whether is a valid persian date
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true
carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false
carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false
carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false

// Whether is a persian leap year
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false
carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false