Skip to content

Instantly share code, notes, and snippets.

@dimm0k
Created August 7, 2013 20:51
Show Gist options
  • Save dimm0k/6178526 to your computer and use it in GitHub Desktop.
Save dimm0k/6178526 to your computer and use it in GitHub Desktop.
[16:46] <+AfterLemon> dimmATwerk: `dR` wrote a regex version of mine, and i cut it down from 10 lines to 2 :]
amTest:="1,12a,100,1:00,01:00,01:00am,14a,01:78"
pmTest:="13,12p,100p,0100p,1:00pm,01:00 p,01:00pm,1300,1300pm,27:00,12:78"
out := ""
loop, parse, amTest, `,
out .= A_LoopField " == " ctime(A_loopfield) "`n"
msgbox % out
out := ""
loop, parse, pmTest, `,
out .= A_LoopField " == " ctime(A_loopfield) "`n"
msgbox % out
cTime(Time){ ; 2013 by dR, edited by AfterLemon
((RegExMatch(Time, "i)^([01]\d|2[0-3]|\d)\s*:?\s*([0-5]\d)?\s*([ap]m?)?$", m)) ? ((RegExMatch(m3, "i)a") && m1 > 12) ? (R := "ERROR") : (((RegExMatch(m3, "i)p") || m3 == "") && m1 >= 12) ? (m1-=12) : ((RegExMatch(m3, "i)a") || m3 == "") && m1 < 12) ? (m1+=12) :)) : (R := "ERROR"))
return ((R!="ERROR") ? (SubStr("00" Mod(m1+=12, 24), -1) ":" SubStr("00" m2, -1)) : ("ERROR"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment