AutoHotkey Community

It is currently May 25th, 2012, 11:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: wrap from 19xx vs 20xx
PostPosted: February 3rd, 2008, 5:38 pm 
if date is 1/2/09 you need to decide if that should be 1909 or 2009.

here is some code that addresses that:
Code:
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
   Else If !RegExMatch(str, "^\W*(\d{1,2}+)(\d{2})\W*$", t)
      RegExMatch(str, "i)(\d{1,2})\s*:\s*(\d{1,2})(?:\s*(\d{1,2}))?(?:\s*([ap]m))?", t)
         , RegExMatch(str, e2, d)
   f = %A_FormatFloat%
   SetFormat, Float, 02.0
   ;deal with wrap around of century based on past-future and offset to allow future
   futureYearsAllowed=10
   FormatTime, thisYear,,yyyy
   StringLeft,thisCen,thisYear,2
   lastCen:=thisCen-1
   StringRight,thisYr,thisYear,2
   thisYr+=futureYearsAllowed

   d := (d3 ? (StrLen(d3) = 2 ? (d3>thisYr ? lastCen:thisCen) : "") . 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
         + (t1 = 12 ? t4 = "am" ? -12.0 : 0.0 : t4 = "am" ? 0.0 : 12.0) . t2 + 0.0 . t3 + 0.0
   SetFormat, Float, %f%
   Return, d
}


Report this post
Top
  
Reply with quote  
PostPosted: February 3rd, 2008, 10:36 pm 
Offline

Joined: January 20th, 2007, 7:47 pm
Posts: 110
i'm working to understand time stuff; what is the objective of the previous two posts? THanks

_________________
...Ed


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 3rd, 2008, 10:51 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
EdScriptNewbie wrote:
i'm working to understand time stuff; what is the objective of the previous two posts? THanks
empyrean5 posted my code for supporting American date formats whereas JDP's modification is a smarter algorithm to detect the millennia for a two digit year such as 08 (2008). If you do not need either of these features the script on my first post should suffice for regular use.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2008, 11:06 pm 
Offline

Joined: January 20th, 2007, 7:47 pm
Posts: 110
thanks! ...Ed

_________________
...Ed


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2009, 8:40 pm 
Below transformation seems not to work
Code:
time := DateParse("2009-Feb-20 11:23:19")

Any suggestions?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2009, 11:40 pm 
Offline

Joined: February 7th, 2009, 5:37 am
Posts: 43
Code:
DateParse("Sat, 07 Mar 2009 13:43:58 GMT")
DateParse("07 Mar 2009 13:43:58")
DateParse("07 Mar 2009 13:43")

returns for me 200903072543


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 31st, 2009, 6:41 pm 
Offline

Joined: April 30th, 2006, 6:23 pm
Posts: 358
Location: Shigle Springs
Titan wrote:
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.

Ya, but if you could put it on the first post, you could save a simpleton like me a few pages of reading!! 8) :wink: :cry: :D :P

_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2009, 9:42 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
I just found your DateParse function, and it works great, thanks for it. I found some scenarios that I want some input on.

Edit:
I forgot to mention that I ran these scenarios on April 12th, 2009. This should clear up confusion when viewed on a later date.

Scenario 1
Code:
Date := "January 2nd, 2009"
FormatTime, FormattedTime, % DateParse(Date), MMMM dd, yyyy

;outputs "April 12, 2009"
MsgBox, % FormattedTime


Scenario 2
Code:
Date := "January 08, 2009 9:05:27"
FormatTime, FormattedTime, % DateParse(Date), MMMM dd, yyyy h:mm:ss

;outputs "January 08, 2009 9:05:00"
MsgBox, % FormattedTime


Scenario 3
In this case, I would expect 09 to be the day. It should have been 2009 if meant to be the year (which your function does support).

Code:
Date := "January 09 9:05:27"
FormatTime, FormattedTime, % DateParse(Date), MMMM dd h:mm:ss

;outputs "April 12 9:05:00"
MsgBox, % FormattedTime

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2009, 10:43 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
animeaime wrote:
Date := "January 09 9:05:27"
animeaime wrote:
Date := "January 2nd, 2009"
My regex was written only for the British date notation which is day-month-year.

animeaime wrote:
Date := "January 08, 2009 9:05:27"
Seems like the code "(?:(Z)|(\+|\-)?" . "(\d{1,2})\6(\d{1,2})" was supposed to handle seconds and time zone offsets as per ISO 8601 but I didn't bother completing this.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2009, 11:40 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Given that, would you be offended if I released my own version of DateParse?

(Edit) I removed the exta, as I realized, I presumed things that I shouldn't have.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2009, 10:23 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
animeaime wrote:
Given that, would you be offended if I released my own version of DateParse?

(Edit) I removed the exta, as I realized, I presumed things that I shouldn't have.



hopefully we all learn from & teach each other. Multiple approaches of same idea in different ways seems beneficial all around.

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2009, 10:27 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Thanks, I always worry that it might come off as "territorial" - like I was trying to outwrite someone else's existing code.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: American Date Format
PostPosted: May 1st, 2009, 9:43 pm 
Offline

Joined: November 21st, 2008, 4:48 pm
Posts: 54
Location: Monterey, California
empyrean5 wrote:
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")

This works great! Thank you, Titan, and empyrean5 for the modification.

- Mike


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 2:57 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
I'm in need of the function addressed by this script (US version), however, it doesn't work when I add in seconds. For example,

Code:
MsgBox % DateParse("3/15/2009 11:22 AM")
;MsgBox message = 200903151122 (correct)

MsgBox % DateParse("3/15/2009 11:22:24 AM")
;MsgBox message = 200903152322 (incorrect)


Is there something I can do to enable the seconds?

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2009, 3:31 pm 
pajenn wrote:
I'm in need of the function addressed by this script (US version), however, it doesn't work when I add in seconds. For example,

Code:
MsgBox % DateParse("3/15/2009 11:22 AM")
;MsgBox message = 200903151122 (correct)

MsgBox % DateParse("3/15/2009 11:22:24 AM")
;MsgBox message = 200903152322 (incorrect)


Is there something I can do to enable the seconds?

Yes, dig in and change the regex. That is what I did (it about drove me nuts getting it right). :)

Here is the code I used. I works with your example
Code:
MsgBox % DateParse("3/15/2009 11:22:24 AM") ; result = 20091503112224

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

   SetFormat, Float, %f%
   Return, d
}


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: infogulch, Opal Monkey and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group