|
@@ -126,7 +126,7 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool {
|
|
|
retCode := CreateTimeLimitCode(data, minutes, start)
|
|
|
if retCode == code && minutes > 0 {
|
|
|
|
|
|
- before, _ := DateParse(start, "YmdHi")
|
|
|
+ before, _ := time.ParseInLocation("200601021504", start, time.Local)
|
|
|
now := time.Now()
|
|
|
if before.Add(time.Minute*time.Duration(minutes)).Unix() > now.Unix() {
|
|
|
return true
|
|
@@ -141,7 +141,7 @@ const TimeLimitCodeLength = 12 + 6 + 40
|
|
|
|
|
|
|
|
|
func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string {
|
|
|
- format := "YmdHi"
|
|
|
+ format := "200601021504"
|
|
|
|
|
|
var start, end time.Time
|
|
|
var startStr, endStr string
|
|
@@ -149,16 +149,16 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
|
|
|
if startInf == nil {
|
|
|
|
|
|
start = time.Now()
|
|
|
- startStr = DateFormat(start, format)
|
|
|
+ startStr = start.Format(format)
|
|
|
} else {
|
|
|
|
|
|
startStr = startInf.(string)
|
|
|
- start, _ = DateParse(startStr, format)
|
|
|
- startStr = DateFormat(start, format)
|
|
|
+ start, _ = time.ParseInLocation(format, startStr, time.Local)
|
|
|
+ startStr = start.Format(format)
|
|
|
}
|
|
|
|
|
|
end = start.Add(time.Minute * time.Duration(minutes))
|
|
|
- endStr = DateFormat(end, format)
|
|
|
+ endStr = end.Format(format)
|
|
|
|
|
|
|
|
|
sh := sha1.New()
|
|
@@ -420,58 +420,3 @@ func Subtract(left interface{}, right interface{}) interface{} {
|
|
|
return fleft + float64(rleft) - (fright + float64(rright))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-var datePatterns = []string{
|
|
|
-
|
|
|
- "Y", "2006",
|
|
|
- "y", "06",
|
|
|
-
|
|
|
-
|
|
|
- "m", "01",
|
|
|
- "n", "1",
|
|
|
- "M", "Jan",
|
|
|
- "F", "January",
|
|
|
-
|
|
|
-
|
|
|
- "d", "02",
|
|
|
- "j", "2",
|
|
|
-
|
|
|
-
|
|
|
- "D", "Mon",
|
|
|
- "l", "Monday",
|
|
|
-
|
|
|
-
|
|
|
- "g", "3",
|
|
|
- "G", "15",
|
|
|
- "h", "03",
|
|
|
- "H", "15",
|
|
|
-
|
|
|
- "a", "pm",
|
|
|
- "A", "PM",
|
|
|
-
|
|
|
- "i", "04",
|
|
|
- "s", "05",
|
|
|
-
|
|
|
-
|
|
|
- "T", "MST",
|
|
|
- "P", "-07:00",
|
|
|
- "O", "-0700",
|
|
|
-
|
|
|
-
|
|
|
- "r", time.RFC1123Z,
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func DateParse(dateString, format string) (time.Time, error) {
|
|
|
- replacer := strings.NewReplacer(datePatterns...)
|
|
|
- format = replacer.Replace(format)
|
|
|
- return time.ParseInLocation(format, dateString, time.Local)
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func DateFormat(t time.Time, format string) string {
|
|
|
- replacer := strings.NewReplacer(datePatterns...)
|
|
|
- format = replacer.Replace(format)
|
|
|
- return t.Format(format)
|
|
|
-}
|