Created
October 28, 2015 20:46
-
-
Save caelifer/4f7fccbabfa35ecb4b8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"regexp" | |
"strings" | |
"time" | |
) | |
var ( | |
timeStampRx = regexp.MustCompile(`^\[(?:[-$0-9])+\]([12]?[0-9]/[1-3]?[0-9]/[0-9]{2} [12]?[0-9]:[0-9]{2}) ([AaPp][Mm]);@`) | |
dateFormat = "1/2/06 3:04PM" | |
) | |
func main() { | |
alltests := strings.Split(`[$-2409]10/2/15 1:24 pm;@ | |
[$-009]9/28/15 2:00 pm;@ | |
[$-5909]10/9/15 1:59 pm;@ | |
[$-4009]10/7/15 4:40 pm;@ | |
[$-5009]1/30/15 10:50 pm;@ | |
[$-1209]11/12/13 4:12 pm;@ | |
[$-1909]10/7/15 5:19 pm;@ | |
[$-3609]10/7/15 5:36 pm;@ | |
[$-3809]1/13/15 2:38 pm;@ | |
[$-4409]1/13/15 4:44 pm;@ | |
[$-3309]11/7/13 8:33 pm;@ | |
[$-1409]10/1/15 2:14 pm;@ | |
[$-509]10/5/15 3:05 pm;@ | |
[$-2609]10/14/15 1:26 pm;@ | |
[$-909]10/9/15 5:09 pm;@ | |
[$-3809]2/6/14 6:38 pm;@ | |
[$-5909]11/5/12 12:59 pm;@ | |
[$-2109]10/2/15 2:21 pm;@ | |
[$-1009]9/15/15 8:10 pm;@ | |
[$-509]10/13/15 5:05 pm;@ | |
[$-109]10/13/15 8:01 pm;@`, "\n") | |
for _, tst := range alltests { | |
res := timeStampRx.FindAllStringSubmatch(tst, -1)[0][1:3] | |
res[1] = strings.ToUpper(res[1]) | |
t0 := strings.Join(res, "") | |
t1, err := time.ParseInLocation(dateFormat, t0, time.Local) | |
if err != nil { | |
log.Println("[WARN] Failed to parse time:", err) | |
} | |
fmt.Printf("%q \t %q\n", t0, t1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live code - http://play.golang.org/p/HYJSJWxoI2
Output: