mIRC Home    About    Download    Register    News    Help

Print Thread
#266135 03/10/19 02:42 PM
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
In $ctime(date string), if parm#1 containing a comma touching the year, it always evaluates the year as 1899. I encountered an RFC presenting a date like

String sDate = "Mar 25 2008, 12:06:30 GMT";

//var -s %a Mar 25 $rand(1601,9999) $+ , 12:06:30 , %b $ctime(%a) , %c $asctime(%b) , %d $gmt(%b)

Removing the $+ allows N to be calculated using the correct year. This behavior has changed across several versions.

//var -s %a Mar 25 2008, 12:06:30 , %b $ctime(%a) , %c $asctime(%b) , %d $gmt(%b)

In 7.57 this returns %b within year 1899
In 7.55 this returns %b as $null
In 6.35 this returns %b within correct year 2008

Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
Thanks for your bug report. A comma has never been valid input to this identifier. It should be returning $null in this case.

It looks like adding support for year range 1601 to 9999 in v7.55 has caused it to handle invalid input differently.

I will be changing this in the next beta so that 1) $null is returned for invalid input as before, and 2) commas are allowed as separators (unless someone can see an issue with backwards compatibility here...)

Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
I can't think of lack of compatibility, unless someone somehow has an almost-a-date string they want to detect from a $null value.

Enabling comma as a delimiter would enable a very common date format

//var -s %a Mar 25, 2008 , %b $ctime(%a) , %c $asctime(%b)
//var -s %a March 25, 2008 , %b $ctime(%a) , %c $asctime(%b)

Looking at the page for https://en.wikipedia.org/wiki/Date_format_by_country
It would be crazy to try to support them all. I do see that the period is a common delimiter used by multiple countries. While mIRC is recognizing them in some formats, one I see used several places that's returning null is: (ddd|dddd) (d|dd). (mmm|mmmm) yyyy

//var -s %a Tuesday 25. Mar 2008 , %b $ctime(%a) , %c $asctime(%b)

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Khaled: Could you give us an exhaustive list of primary date/time formats accepted as input to $ctime(), and then discuss the minor variations or deviations that will also be detected and accepted for each type? (It would assist me in framing the boundaries of this bug.)

The help file specifies the following four formats are recognized:

Code
January 1 1970 00:00:00
3rd August 1987 3:46pm
21/4/72 1:30:37
Wed 1998-3-27 21:16

Of these formats, the user can deviate by omitting certain portions, such as the time (h:m:s) so that the current clock-time is assumed.

We can also see that these formats work:

Code
3 Aug 1987  /* a variation of 3rd August 1987 3:46pm */
1998-03-27  /* a variation of Wed 1998-3-27 21:16 */

Are you using conventional C++ string array parsing, or regular expression parsing? If regular expression parsing, would you share the regex patterns with us?

If I were better informed of the different standard ISO date-time formats, I could articulate this post better, but I'm not there yet.

Also, did we arrive yet at a consensus to recognize $gmt(n) or $gmt($ctime(<date>)) as acceptable use of $gmt()? ((i think it should be))

---
One minor suggestion for added support for date-time recognition and assumption-making in $ctime():
If only a time value is passed, but no date value, then assume the current date. As in $ctime(13:00:59) or $ctime(5:00 p.m.) Below is pseudo-code.
This is similar in behavior to how $ctime() handles a date value with no time value, just in reverse, as it assumes the current time instead.

Code
if ($regex($1-,/^[0-9:apm. ]+$/i)) { tokenize 32 $date $1- }

Last edited by Raccoon; 11/11/19 11:56 PM.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
The exhaustive list is in the help file. If you find that $ctime() is not fully documented, please let me know and I will update the help file.

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
This is what I believe I learned from fuzzing $ctime() with innumerous date/time strings.

Basically mIRC just reads from left-to-right trying to identify any date/time parts that it comes across, then fills in an internal variable for that given part.
Upon further inspection, mIRC performs at least 3 distinct passes to parse different values, so I'll segment this in order of those passes.
The order of these passes determines which time date parts will be overwritten if they occur twice in the string.

Any portion of the time and date can appear in ANY order, as long as all internal variables are filled (h m s optional).
Any portion of the time and date can appear multiple times, and it will overwrite previous values,

Quote
Internal variables are: Month, Date, Year, Hour, Minute, Second

Pass 1
If we encounter a number from 1 to 31, update our DATE variable.
If we encounter a number from 32 to 99 or 1601 to 9999, update our YEAR variable.
* years 32 to 99 are assumed 1900's.

Pass 2
If either structure d/d/d or d-d-d is encountered, as in 1/1/1 or 29-2-28
the center number is always the month,
try the left number as the day and the right number as the year,
if that's an invalid calendar date, then try the left number as the year and the right number as the day,
* years 39 to 99 are assumed 1900's and years 0 through 38 are 2000's.

Pass 2.5
If we encounter a d:d:d or d:d structure, treat it as h:m:s or h:m and update the HOUR, MINUTE and SECONDS variables.
If we encounter "pm" or "PM" (but no periods) then add 12 to the HOUR variable if it's less-than 12.
* (am and AM are just ignored)

Pass 3
If we encounter the first 3 letters of a month, ignore the rest of the spelling and update our MONTH variable.

Incidentals:

Random words that aren't touching are ignored. Day-Of-Week are ignored. "am" and "AM" are ignored in Pass 2.
The ordinal suffixes "st", "nd", "rd", "th" that are touching a 1 to 2 digit number are stripped and ignored in Pass 1.
Zero padding is stripped and ignored. Any number anywhere can be ridiculously zero-padded.
xxx However, any other random characters that prefix or suffix a number will invalidate the function.
/* This should probably be fixed --- that would solve a host a formatting issues, like comma usage.
You could strip and ignore random suffixing characters like you do with ordinals st nd rd th. */

Example: 02 1/1/1 Feb 01:23 Apricot 2019 pm
Result: Sun Apr 01 13:23:00 2001


Is that correct?

Last edited by Raccoon; 12/11/19 10:39 PM.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
That looks about right.

That said, I am not going to write all of that in the help file.

The purpose of the help file is to give an overall description of how a feature works, with some examples, not to provide pseudo-code that mirrors every possible if statement, exception, etc. in the actual code.

In fact, I wouldn't depend on the above pseudo-code at all, because I might change the code completely in the future.

Joined: Aug 2003
Posts: 319
P
Pan-dimensional mouse
Offline
Pan-dimensional mouse
P
Joined: Aug 2003
Posts: 319
I agree with Khaled's philosophy here - the Help file should not document every quirk - that is what forums are for.

But please feel free to add the psuedo-code to the WikiChip page https://en.wikichip.org/wiki/mirc/identifiers/$ctime

Last edited by Protopia; 12/11/19 10:53 PM. Reason: Add a missing "not" so it makes sense.
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Honestly, I wasn't even asking about the help file. I don't really care about the help file. Not saying that it couldn't use some more information, but that's not why I came here. My elaboration was strictly so I could analyze the mechanics of how $ctime() works in order to become a better beta tester.

Though feel free to borrow from this.

Quote
$ctime(text)
Returns the number of seconds elapsed since 00:00:00 GMT, January 1, 1970 based on the date that you specify.
Accepts any date format that contains "Jan" to "Dec" for month, numbers 1 to 31 for day, numbers 32 to 99 or 1601 to 9999 for year, or the shorthand d/m/y, y/m/d, d-m-y, and y-m-d. But not m/d/y or m-d-y. Optionally, may also include the time of day in h:m or h:m:s as 12h or 24h format.

$ctime(January 1 1970 00:00:00)
$ctime(3rd August 1987 3:46pm)
$ctime(21/4/72 1:30:37)
$ctime(Wed 1998-3-27 21:16)


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Aug 2003
Posts: 319
P
Pan-dimensional mouse
Offline
Pan-dimensional mouse
P
Joined: Aug 2003
Posts: 319
Ah - now if we are talking about testing...

What we really need is a community effort to build a comprehensive regression test script (on GitHub perhaps) that tries to test as many variants of each element of mSL as it can.


Link Copied to Clipboard