Skip to content

Commit

Permalink
Add ToShortMonthString,ToShortWeekString methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Dec 2, 2024
1 parent 175ed04 commit 9dde7c3
Show file tree
Hide file tree
Showing 5 changed files with 578 additions and 78 deletions.
28 changes: 22 additions & 6 deletions calendar/persian/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,33 @@ carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
// 获取波斯历小时
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
// 获取波斯历分钟
carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
// 获取波斯历秒数
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15

// 获取波斯历日期时间字符串
carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 1399-05-15 13:14:15
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 1399-05-15 13:14:15
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

// 获取波斯历月字符串
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // مرداد
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") // مرداد

// 获取简写波斯历月字符串
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") // مرد

// 获取波斯历周字符串
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // چهارشنبه
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") // چهارشنبه

// 获取简写波斯历周字符串
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") // د

```

Expand Down
24 changes: 20 additions & 4 deletions calendar/persian/README.jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,28 @@ carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15

// ペルシャ暦日時文字列の取得
carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 1399-05-15 13:14:15
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 1399-05-15 13:14:15
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

// ペルシア暦月文字列の取得
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // مرداد
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") // مرداد

// 略語ペルシャ暦文字列の取得
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") // مرد

// ペルシャ暦週文字列の取得
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // چهارشنبه
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") // چهارشنبه

// 略語ペルシャ暦週文字列の取得
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") // د
```

##### ペルシャ暦を西暦に変換する
Expand Down
28 changes: 22 additions & 6 deletions calendar/persian/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,28 @@ carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15

// Get persian date and time string
carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 1399-05-15 13:14:15
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 1399-05-15 13:14:15
// // Get persian month as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // مرداد
// // Get persian week as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // چهارشنبه
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") // د

```

Expand Down
79 changes: 73 additions & 6 deletions calendar/persian/persian.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ import (
)

var (
months = []string{"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"}
weeks = []string{"یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"}
EnMonths = []string{"Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"}
ShortEnMonths = []string{"Far", "Ord", "Kho", "Tir", "Mor", "Sha", "Meh", "Aba", "Aza", "Dey", "Bah", "Esf"}

FaMonths = []string{"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"}
ShortFaMonths = []string{"فرو", "ارد", "خرد", "تیر", "مرد", "شهر", "مهر", "آبا", "آذر", "دی", "بهم", "اسف"}

EnWeeks = []string{"Yekshanbeh", "Doshanbeh", "Seshanbeh", "Chaharshanbeh", "Panjshanbeh", "Jomeh", "Shanbeh"}
ShortEnWeeks = []string{"Yek", "Dos", "Ses", "Cha", "Pan", "Jom", "Sha"}

FaWeeks = []string{"نجشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"}
ShortFaWeeks = []string{"پ", "چ", "س", "د", "ی", "ش", "ج"}

InvalidDateError = func() error {
return fmt.Errorf("invalid persian date, please make sure the date is valid")
Expand Down Expand Up @@ -195,20 +204,78 @@ func (p Persian) String() string {

// ToMonthString outputs a string in persian month format like "فروردین".
// 获取完整月份字符串,如 "فروردین"
func (p Persian) ToMonthString() (month string) {
func (p Persian) ToMonthString(locale ...string) (month string) {
if !p.IsValid() {
return ""
}
return months[p.month-1]
loc := "en"
if len(locale) > 0 {
loc = locale[0]
}
switch loc {
case "en":
return EnMonths[p.month-1]
case "fa":
return FaMonths[p.month-1]
}
return ""
}

// ToShortMonthString outputs a short string in persian month format like "فروردین".
// 获取缩写月份字符串,如 "فروردین"
func (p Persian) ToShortMonthString(locale ...string) (month string) {
if !p.IsValid() {
return ""
}
loc := "en"
if len(locale) > 0 {
loc = locale[0]
}
switch loc {
case "en":
return ShortEnMonths[p.month-1]
case "fa":
return ShortFaMonths[p.month-1]
}
return ""
}

// ToWeekString outputs a string in week layout like "چهارشنبه".
// 输出完整星期字符串,如 "چهارشنبه"
func (p Persian) ToWeekString() (month string) {
func (p Persian) ToWeekString(locale ...string) (month string) {
if !p.IsValid() {
return ""
}
loc := "en"
if len(locale) > 0 {
loc = locale[0]
}
switch loc {
case "en":
return EnWeeks[p.ToGregorian().Week()]
case "fa":
return FaWeeks[p.ToGregorian().Week()]
}
return ""
}

// ToShortWeekString outputs a short string in week layout like "چهارشنبه".
// 输出缩写星期字符串,如 "چهارشنبه"
func (p Persian) ToShortWeekString(locale ...string) (month string) {
if !p.IsValid() {
return ""
}
return weeks[p.ToGregorian().Week()]
loc := "en"
if len(locale) > 0 {
loc = locale[0]
}
switch loc {
case "en":
return ShortEnWeeks[p.ToGregorian().Week()]
case "fa":
return ShortFaWeeks[p.ToGregorian().Week()]
}
return ""
}

// IsValid reports whether is a valid persian date.
Expand Down
Loading

0 comments on commit 9dde7c3

Please sign in to comment.