AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Date parser - convert any date format to YYYYMMDDHH24MISS
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
ManaUser



Joined: 24 May 2007
Posts: 901

PostPosted: Sat Jun 30, 2007 9:05 pm    Post subject: Reply with quote

I think there's a problem with the handling of AM and PM for 12 O'Clock.

It fails to take into account that 12 am in midnight and 12 pm is noon, not the reverse.

For example:
2:30 am = 200706300230
2:30 pm = 200706301430
Which is correct, but:
12:30 am = 200706301230
12:30 pm = 200706302430
Which is not. 24:30 doens't even exist.

This will be a very useful function if that can be fixed though. I'd try to fix it myself, but your RegEx is way beyond me.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Sat Jun 30, 2007 9:23 pm    Post subject: Reply with quote

Thanks, I believe it has been fixed in version 1.03.
It was due to a miscalculation in my expressions, not regex Wink
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
ManaUser



Joined: 24 May 2007
Posts: 901

PostPosted: Sun Jul 01, 2007 8:50 am    Post subject: Reply with quote

I'm afraid I'm still getting wierd results. Now for either "12:30 AM" or "12:30 PM" I'm getting 20070701030 which aside from being wrong for pm, is one too few digits. Sad Once again times other than 12 work correctly.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Sun Jul 01, 2007 11:09 am    Post subject: Reply with quote

In 1.04:

12:30 am: 200707010030
12:30 pm: 200707011230
1:30 am: 200707010130
6:37 pm 15 October 2009: 200910151837
12:30: 200707011230 (assumed pm time on it's own)
1:30: 200707011330 (like above)

I hope everything works now.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
ManaUser



Joined: 24 May 2007
Posts: 901

PostPosted: Sun Jul 01, 2007 4:32 pm    Post subject: Reply with quote

Works great now! Very Happy
Back to top
View user's profile Send private message
silveredge78



Joined: 25 Jul 2006
Posts: 382
Location: Midwest, USA

PostPosted: Sat Oct 20, 2007 7:46 am    Post subject: Reply with quote

Titan,

Perhaps I was just a bit fried, but I couldn't get it to work for a simple date structure like, 1/1/2007 or 10/21/07. Does this take care of those? It would be great to have an all-inclusive function. Smile
_________________
SilverEdge78
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Sat Oct 20, 2007 10:16 am    Post subject: Reply with quote

1/1/2007 gives 20070101 which is correct. Your second date has the month and day mixed around, I realize it's the American format but it's not how I implemented my function.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
silveredge78



Joined: 25 Jul 2006
Posts: 382
Location: Midwest, USA

PostPosted: Sat Oct 20, 2007 5:28 pm    Post subject: Reply with quote

So 1/1/07 works only because it's the same with the month/day in either position. I imagine then that 1/31/07 would not work. Would you be up for the task for allowing the American variant of date to work using this? Or is that too hard to add in there? I don't know RegEx at all, so when I look at your function, it only makes a little sense.

I ended up making up my own translation thing to use, but it definitely doesn't use RegEx. It uses StringSplit on / and then checks the length of the string to see if it needs a 0 before the day/month.

Thanks for the clarification.
_________________
SilverEdge78
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Sat Oct 20, 2007 6:39 pm    Post subject: Reply with quote

silveredge78 wrote:
Would you be up for the task for allowing the American variant of date to work using this?
If I did that, British/European formats won't work. Instead you could word the months or use ISO date, i.e. 1st April 2007 or 2007-04-1.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
silveredge78



Joined: 25 Jul 2006
Posts: 382
Location: Midwest, USA

PostPosted: Sat Oct 20, 2007 8:02 pm    Post subject: Reply with quote

I would do that happily if I could. I am pulling the data from an SQL database that has the date stored as 10/31/2007 (american). I figured if you tried to account for our version, that it would break the european way. So no worries. But I will see if i can use your script in other things that I do. It is a good script for certain. Smile

Ooo...could you make two versions of the script? One for the european and one for the american? Like, v1.4A and v1.4E, where the only difference is that specific date format change.

Just a thought!
_________________
SilverEdge78
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Sat Oct 20, 2007 9:01 pm    Post subject: Reply with quote

silveredge78 wrote:
Ooo...could you make two versions of the script? One for the european and one for the american?
All you need to do is add the highlighted line before the main function proc.:

Code:
DateParse(str) {
   static e2 = "i)(?:(\d{1, ; [...]
   str := RegExReplace(str, "(\d{1,2})(\D+)(\d{1,2})", "$3$2$1")


Alternatively you can use the same regex before you make the function call.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
Ace_NoOne



Joined: 10 Oct 2005
Posts: 333
Location: Germany

PostPosted: Sun Oct 21, 2007 7:44 pm    Post subject: Reply with quote

How about an optional second parameter, Titan? Something like this:
Code:
DateParse(str, sillyFormat = false) {
   if(sillyFormat) { // US locale
      str := RegExReplace(str, "(\d{1,2})(\D+)(\d{1,2})", "$3$2$1")
   }
   // further processing
}
Or, as suggested before, we simply coerce everyone into adopting ISO 8601...

silveredge78 wrote:
an SQL database that has the date stored as 10/31/2007 (american)
Sounds like a case for The Daily WTF...
_________________
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Sun Oct 21, 2007 9:11 pm    Post subject: Reply with quote

For such a trivial mod users can refer to the info on this thread. Incorporating it to my official release breaks the simplicity of a single parameter and introduces culture variation dependence which can be complicated given the extra parsing rules, word translations, etc.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
silveredge78



Joined: 25 Jul 2006
Posts: 382
Location: Midwest, USA

PostPosted: Mon Oct 22, 2007 4:58 am    Post subject: Reply with quote

Titan, that is easy for me to do. Thanks for throwing that up here. I don't think it necessary to pass a second parameter. If I'm the first one in a year to offer this up as a concern, I don't think it really is one. As for the formating, perhaps its cause its being exported to CSV? I don't know. I just have to process the file.

Thanks again Titan!
_________________
SilverEdge78
Back to top
View user's profile Send private message
empyrean5
Guest





PostPosted: Sun Jan 20, 2008 4:54 pm    Post subject: American Date Format Reply with quote

I needed to make the following change to make American Date Format mm/dd/yyyy hh:mm.... work:

Code:
DateParse(str) {
   static e2 = "i)(?:(\d{1, ; [...]
   str := RegExReplace(str, "(\d{1,2})(\D+)(\d{1,2})(.*)", "$3$2$1$4")
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group