Skip to content

Commit

Permalink
FormatType constans name fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyaozclk committed Nov 22, 2020
1 parent 0268dd5 commit 500f3ea
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 109 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ Import all necessary packages.("fmt" - Print, "time" - Getting time from machine

| | Token | Output |
|----------------|-------|----------------------------------------|
| Month | M | 1 2 ... 11 12 |
| | MM | 01 01 ... 11 12 |
| | MMM | Jan Feb ... Nov Dec |
| | MMMM | January February ... November December |
| Day of Month | D | 1 2 ... 30 31 |
| | DD | 01 02 ... 30 31 |
| | DDDD | Mon, Tue ... Sat Sun |
| | DDDDD | Monday, Tuesday ... Saturday Sunday |
| Day of Year | DDD | 1 2 ... 364 365 |
| Year | YY | 70 71 ... 29 30 |
| | YYYY | 1970 1971 ... 2029 2030 |
| Quarter | Q | 1 2 3 4 |
| AM/PM | A | AM PM |
| | a | am pm |
| Hour | H | 0 1 ... 22 23 |
| | HH | 00 01 ... 22 23 |
| | h | 1 2 ... 11 12 |
| | hh | 01 02 ... 11 12 |
| Minute | m | 0 1 ... 58 59 |
| | mm | 00 01 ... 58 59 |
| Second | s | 0 1 ... 58 59 |
| | ss | 00 01 ... 58 59 |
| Time Zone | Z | -07:00 -06:00 ... +06:00 +07:00 |
| | ZZ | -0700 -0600 ... +0600 +0700 |
| Unix Timestamp | X | 1360013296 |
| Month | TIME_M | 1 2 ... 11 12 |
| | TIME_MM | 01 01 ... 11 12 |
| | TIME_MMM | Jan Feb ... Nov Dec |
| | TIME_MMMM | January February ... November December |
| Day of Month | TIME_D | 1 2 ... 30 31 |
| | TIME_DD | 01 02 ... 30 31 |
| | TIME_DDDD | Mon, Tue ... Sat Sun |
| | TIME_DDDDD | Monday, Tuesday ... Saturday Sunday |
| Day of Year | TIME_DDD | 1 2 ... 364 365 |
| Year | TIME_YY | 70 71 ... 29 30 |
| | TIME_YYYY | 1970 1971 ... 2029 2030 |
| Quarter | TIME_Q | 1 2 3 4 |
| AM/PM | TIME_A | AM PM |
| | TIME_a | am pm |
| Hour | TIME_H | 0 1 ... 22 23 |
| | TIME_HH | 00 01 ... 22 23 |
| | TIME_h | 1 2 ... 11 12 |
| | TIME_hh | 01 02 ... 11 12 |
| Minute | TIME_m | 0 1 ... 58 59 |
| | TIME_mm | 00 01 ... 58 59 |
| Second | TIME_s | 0 1 ... 58 59 |
| | TIME_ss | 00 01 ... 58 59 |
| Time Zone | TIME_Z | -07:00 -06:00 ... +06:00 +07:00 |
| | TIME_ZZ | -0700 -0600 ... +0600 +0700 |
| Unix Timestamp | TIME_X | 1360013296 |
50 changes: 25 additions & 25 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,97 +31,97 @@ var languageMonthsMap = map[LocaleType][]string{
}

var formatFuncsMap = map[FormatType]func(to ToOpts) string{
D: func(to ToOpts) string {
TIME_D: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Day())
},
DD: func(to ToOpts) string {
TIME_DD: func(to ToOpts) string {
return fmt.Sprintf("%02d", to.time.Day())
},
DDD: func(to ToOpts) string {
TIME_DDD: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.YearDay())
},
DDDD: func(to ToOpts) string {
TIME_DDDD: func(to ToOpts) string {
return languageDaysMap[to.locale][to.time.Weekday()][:3]
},
DDDDD: func(to ToOpts) string {
TIME_DDDDD: func(to ToOpts) string {
return languageDaysMap[to.locale][to.time.Weekday()]
},
M: func(to ToOpts) string {
TIME_M: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Month())
},
MM: func(to ToOpts) string {
TIME_MM: func(to ToOpts) string {
return fmt.Sprintf("%02d", to.time.Month())
},
MMM: func(to ToOpts) string {
TIME_MMM: func(to ToOpts) string {
return languageMonthsMap[to.locale][to.time.Month()-1][:3]
},
MMMM: func(to ToOpts) string {
TIME_MMMM: func(to ToOpts) string {
return languageMonthsMap[to.locale][to.time.Month()-1]
},
YY: func(to ToOpts) string {
TIME_YY: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Year())[2:]
},
YYYY: func(to ToOpts) string {
TIME_YYYY: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Year())
},
Q: func(to ToOpts) string {
TIME_Q: func(to ToOpts) string {
return fmt.Sprintf("%d", (to.time.Month()/4)+1)
},
A: func(to ToOpts) string {
TIME_A: func(to ToOpts) string {
if to.time.Hour() >= 12 {
return "PM"
} else {
return "AM"
}
},
a: func(to ToOpts) string {
TIME_a: func(to ToOpts) string {
if to.time.Hour() >= 12 {
return "pm"
} else {
return "am"
}
},
H: func(to ToOpts) string {
TIME_H: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Hour())
},
HH: func(to ToOpts) string {
TIME_HH: func(to ToOpts) string {
return fmt.Sprintf("%02d", to.time.Hour())
},
h: func(to ToOpts) string {
TIME_h: func(to ToOpts) string {
if to.time.Hour() > 12 {
return fmt.Sprintf("%d", to.time.Hour()-12)
} else {
return fmt.Sprintf("%d", to.time.Hour())
}
},
hh: func(to ToOpts) string {
TIME_hh: func(to ToOpts) string {
if to.time.Hour() > 12 {
return fmt.Sprintf("%02d", to.time.Hour()-12)
} else {
return fmt.Sprintf("%02d", to.time.Hour())
}
},
m: func(to ToOpts) string {
TIME_m: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Minute())
},
mm: func(to ToOpts) string {
TIME_mm: func(to ToOpts) string {
return fmt.Sprintf("%02d", to.time.Minute())
},
s: func(to ToOpts) string {
TIME_s: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Second())
},
ss: func(to ToOpts) string {
TIME_ss: func(to ToOpts) string {
return fmt.Sprintf("%02d", to.time.Second())
},
Z: func(to ToOpts) string {
TIME_Z: func(to ToOpts) string {
name, _ := to.time.Zone()
return fmt.Sprintf("%s:00", name)
},
ZZ: func(to ToOpts) string {
TIME_ZZ: func(to ToOpts) string {
name, _ := to.time.Zone()
return fmt.Sprintf("%s00", name)
},
X: func(to ToOpts) string {
TIME_X: func(to ToOpts) string {
return fmt.Sprintf("%d", to.time.Unix())
},
}
Expand Down
Loading

0 comments on commit 500f3ea

Please sign in to comment.