|
5 | 5 | package idvalidator |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "fmt" |
8 | 9 | "math" |
9 | 10 | "math/rand" |
10 | 11 | "regexp" |
@@ -111,9 +112,9 @@ func getRandAddressCode(pattern string) string { |
111 | 112 | func generatorBirthdayCode(addressCode string, address string, birthday string) string { |
112 | 113 | startYear := "0001" |
113 | 114 | endYear := "9999" |
114 | | - year := datePipelineHandle(datePad(substr(birthday, 0, 4), "year"), "year") |
115 | | - month := datePipelineHandle(datePad(substr(birthday, 4, 6), "month"), "month") |
116 | | - day := datePipelineHandle(datePad(substr(birthday, 6, 8), "day"), "day") |
| 115 | + year := datePipeHandle(datePad(substr(birthday, 0, 4), "year"), "year") |
| 116 | + month := datePipeHandle(datePad(substr(birthday, 4, 6), "month"), "month") |
| 117 | + day := datePipeHandle(datePad(substr(birthday, 6, 8), "day"), "day") |
117 | 118 |
|
118 | 119 | addressCodeInt := cast.ToInt(addressCode) |
119 | 120 | if _, ok := data.AddressCodeTimeline[addressCodeInt]; ok { |
@@ -151,7 +152,7 @@ func generatorBirthdayCode(addressCode string, address string, birthday string) |
151 | 152 | } |
152 | 153 |
|
153 | 154 | // 日期处理 |
154 | | -func datePipelineHandle(date string, category string) string { |
| 155 | +func datePipeHandle(date string, category string) string { |
155 | 156 | dateInt := cast.ToInt(date) |
156 | 157 |
|
157 | 158 | switch category { |
@@ -196,13 +197,5 @@ func datePad(date string, category string) string { |
196 | 197 | padLength = 4 |
197 | 198 | } |
198 | 199 |
|
199 | | - for i := 0; i < padLength; i++ { |
200 | | - length := len([]rune(date)) |
201 | | - if length < padLength { |
202 | | - // date = fmt.Sprintf("%s%s", "0", date) |
203 | | - date = "0" + date |
204 | | - } |
205 | | - } |
206 | | - |
207 | | - return date |
| 200 | + return fmt.Sprintf(fmt.Sprintf("%%0%ds", padLength), date) |
208 | 201 | } |
0 commit comments