Icarus wrote:
Actually, I also have some problem with the hour returning as "25" as was mentioned earlier in this thread.
This: Mon, 17 Aug 2009 13:23:33 GMT
Returned this: 200908172523
EDIT:
Also, as far as I could figure out, there is no adjustment to local time, so this is losing data - the above example will render a timestamp that cannot be compared to anything other than stamps that came from the same source.
Did I miss anything?
Yes, there is no provision for local/gmt corrections. Also, none of code in this thread allow for "Mon, ..." or GMT in the passed string. Further more, none of the variations of this function support seconds, except those I posted.
Your example
Mon, 17 Aug 2009 13:23:33 GMT if passed as
17 Aug 2009 13:23:33 will work with the euro format version that I posted here
http://www.autohotkey.com/forum/post-268817.html#268817
The US version is posted here
http://www.autohotkey.com/forum/post-268830.html#268830
Your test case works with the euro version if you limit the string to the only the required parts.
Code:
MsgBox % DateParse("17 Aug 2009 13:23:33") ; = 20090817132333
DateParse(str) {
static e2 = "i)(?:(\d{1,2}+)[\s\.\-\/,]+)?(\d{1,2}|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*)[\s\.\-\/,]+(\d{2,4})"
str := RegExReplace(str, "((?:" . SubStr(e2, 42, 47) . ")\w*)(\s*)(\d{1,2})\b", "$3$2$1", "", 1)
If RegExMatch(str, "i)^\s*(?:(\d{4})([\s\-:\/])(\d{1,2})\2(\d{1,2}))?"
. "(?:\s*[T\s](\d{1,2})([\s\-:\/])(\d{1,2})(?:\6(\d{1,2})\s*(?:(Z)|(\+|\-)?"
. "(\d{1,2})\6(\d{1,2})(?:\6(\d{1,2}))?)?)?)?\s*$", i)
d3 := i1, d2 := i3, d1 := i4, t1 := i5, t2 := i7, t3 := i8, t4 := t1 >11 ? "pm" : "am"
Else If !RegExMatch(str, "x)^\W* (\d{1,2}?) (\d{2}) (\d{2}+)? (?:\s*([ap]m))? \W* $", t)
RegExMatch(str, "ix)(\d{1,2}) \s* : \s* (\d{1,2}) (?:(?:\s*:\s*) (\d{1,2}))? (?:\s*([ap]m))?", t)
, RegExMatch(str, e2, d)
f = %A_FormatFloat%
SetFormat, Float, 02.0
d := (d3 ? (StrLen(d3) = 2 ? 20 : "") . d3 : A_YYYY)
. ((d2 := d2 + 0 ? d2 : (InStr(e2, SubStr(d2, 1, 3)) - 40) // 4 + 1.0) > 0
? d2 + 0.0 : A_MM). ((d1 += 0.0) ? d1 : A_DD) . t1
+ (((t4 = "pm") && (t1 < 12)) ? +12.0 : 0.0) . t2 +0.0 . t3 + 0.0 ; use this one - defaults to AM
SetFormat, Float, %f%
Return, d
}