Date comparison logic inverted?

Hi All,

We're using DOORS 9.3.

This code
{
Date d1 = date("2 November 2010")
Date d2 = date("3 November 2010")

print (d1 == d2) "\n"
print (d1 != d2) "\n"
print (d1 < d2) "\n"
print (d1 > d2) "\n"
print (d1 <= d2) "\n"
print (d1 >= d2) "\n"
}

produces the following output on my machine:
{
true
false
false
false
true
true
}

It appears that the logic output is inverted under some operators when comparing two dates. What am I missing?

Thanks in advance for your help.
LIMoon - Sun Jan 23 19:04:07 EST 2011

Re: Date comparison logic inverted?
SystemAdmin - Sun Jan 23 19:21:27 EST 2011

Whoooa - that is weird.

I don't have 9.3 loaded yet but I tried your script on v9.2.0.3 (build 92412) and I got the following results compared with yours.
 

Logic           my results      your results
(d1 == d2)      false           true
(d1 != d2)      true            false
(d1 < d2)    true            false  
(d1 > d2)    false           false  //match
(d1 <= d2)   true            true   //match
(d1 >= d2)   false           true

 


All of my results are what you would expect. Of your results, two matched, the rest are reversed. That's weird.

Hopefully someone with 9.3 can confirm what you're experiencing, if so, that's a defect in 9.3.

 

 

 


Paul Miller
Melbourne, Australia

 

 

Re: Date comparison logic inverted?
PDU - Mon Jan 24 02:01:41 EST 2011

SystemAdmin - Sun Jan 23 19:21:27 EST 2011

Whoooa - that is weird.

I don't have 9.3 loaded yet but I tried your script on v9.2.0.3 (build 92412) and I got the following results compared with yours.
 

Logic           my results      your results
(d1 == d2)      false           true
(d1 != d2)      true            false
(d1 < d2)    true            false  
(d1 > d2)    false           false  //match
(d1 <= d2)   true            true   //match
(d1 >= d2)   false           true

 


All of my results are what you would expect. Of your results, two matched, the rest are reversed. That's weird.

Hopefully someone with 9.3 can confirm what you're experiencing, if so, that's a defect in 9.3.

 

 

 


Paul Miller
Melbourne, Australia

 

 

Hello,

i think it is not a version problem, but a dat eformat problem.

I try with 9.1 and french PC.

With :

Date d1 = date("2 November 2010")
Date d2 = date("3 November 2010")
print "date=" d1 "\n" 
print "date=" d2 "\n" 
print (d1 == d2) "\n"

 


I have :
date=
date=
true

With :

 

 

Date d1 = date("2/11/2010")
Date d2 = date("3/11/2010")
print "date=" d1 "\n" 
print "date=" d2 "\n" 
print (d1 == d2) "\n"



I have :
date=02 November 2010
date=03 November 2010
false

And with :



 

 

Date d1 = "02 November 2010"
Date d2 = "03 November 2010"
print "date=" d1 "\n" 
 
I have :
date=02 November 2010
date=03 November 2010
false
print "date=" d2 "\n" 
print (d1 == d2) "\n"

 

Re: Date comparison logic inverted?
Mathias Mamsch - Mon Jan 24 07:55:30 EST 2011

When parsing string dates (and also when printing dates) DOORS will try to use the default locale, so you should ALWAYS pass the format identifier! The solution to your riddle is, that the date will be passed to (null), therefore you get the equality.

Try the below instead! Regards, Mathias
 

{
Date d1 = date("2 November 2010", "dd MMMM yyyy")
Date d2 = date("3 November 2010", "dd MMMM yyyy")
 
print (d1 == d2) "\n"
print (d1 != d2) "\n"
print (d1 < d2) "\n"
print (d1 > d2) "\n"
print (d1 <= d2) "\n"
print (d1 >= d2) "\n"
}
 
{
Date d1 = date("2 November 2010")
print intOf d1
}

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Date comparison logic inverted?
llandale - Mon Jan 24 17:35:44 EST 2011

This is a "Locales" issue. Add the following to the end of your DXL and you will see that your dates are null:
print "null dates: " (null d1) "\t" (null d2) "\n"
print "D1: \t" stringOf(d1) "\n"
print "D2: \t" stringOf(d2) "\n"

It prints null, then aborts at the stringOf command. Null Dates will produce your results.

Mathias will no doubt survive the nulls and print the Dates as those are legal date formats for him So "2 November 2010" is illegal for you and I but not for Mathias; no doubt one of those "Anglo" things.

I use format "2011-Jan-21" and "2011-01-21" because its unambiguous and I cannot stand the US format; but those are illegal also, so I wrote my own converter. The "-Jan-" in reports that will not be sorted Alpha, "-01-" in file names and columns that may be sorted.

  • Louie

Re: Date comparison logic inverted?
LIMoon - Tue Jan 25 05:15:16 EST 2011

PDU - Mon Jan 24 02:01:41 EST 2011

Hello,

i think it is not a version problem, but a dat eformat problem.

I try with 9.1 and french PC.

With :

Date d1 = date("2 November 2010")
Date d2 = date("3 November 2010")
print "date=" d1 "\n" 
print "date=" d2 "\n" 
print (d1 == d2) "\n"

 


I have :
date=
date=
true

With :

 

 

Date d1 = date("2/11/2010")
Date d2 = date("3/11/2010")
print "date=" d1 "\n" 
print "date=" d2 "\n" 
print (d1 == d2) "\n"



I have :
date=02 November 2010
date=03 November 2010
false

And with :



 

 

Date d1 = "02 November 2010"
Date d2 = "03 November 2010"
print "date=" d1 "\n" 
 
I have :
date=02 November 2010
date=03 November 2010
false
print "date=" d2 "\n" 
print (d1 == d2) "\n"

 

Thank you for the date formatting tip, Pierre.

Re: Date comparison logic inverted?
LIMoon - Tue Jan 25 05:17:44 EST 2011

LIMoon - Tue Jan 25 05:15:16 EST 2011
Thank you for the date formatting tip, Pierre.

Thank you for the date formatting/locale tips, Mathias and Louie. As always, you folks are a great help to the DXL user community!

Re: Date comparison logic inverted?
llandale - Tue Jan 25 09:32:58 EST 2011

LIMoon - Tue Jan 25 05:17:44 EST 2011
Thank you for the date formatting/locale tips, Mathias and Louie. As always, you folks are a great help to the DXL user community!

Yes, we know!

Re: Date comparison logic inverted?
MyDeveloerWorks - Fri Mar 28 06:13:56 EDT 2014

Mathias Mamsch - Mon Jan 24 07:55:30 EST 2011

When parsing string dates (and also when printing dates) DOORS will try to use the default locale, so you should ALWAYS pass the format identifier! The solution to your riddle is, that the date will be passed to (null), therefore you get the equality.

Try the below instead! Regards, Mathias
 

{
Date d1 = date("2 November 2010", "dd MMMM yyyy")
Date d2 = date("3 November 2010", "dd MMMM yyyy")
 
print (d1 == d2) "\n"
print (d1 != d2) "\n"
print (d1 < d2) "\n"
print (d1 > d2) "\n"
print (d1 <= d2) "\n"
print (d1 >= d2) "\n"
}
 
{
Date d1 = date("2 November 2010")
print intOf d1
}

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Sorry to be opening this topic again, but I tried running the commands above recommended by Mathias and the results were still inverted.

When I appended Louies code I go errors:

-E- DXL: <Line:17> incorrect arguments for function (null)

I have a Spanish PC and tested on  DOORS 8.3 and 9.5.2

I had to modify it as follows to get it to work

{
Date d1 = date("2-11-2010",userLocale, "dd-MM-yyyy")
Date d2 = date("3-11-2010",userLocale, "dd-MM-yyyy")
 
print (d1 == d2) "\n"
print (d1 != d2) "\n"
print (d1 < d2) "\n"
print (d1 > d2) "\n"
print (d1 <= d2) "\n"
print (d1 >= d2) "\n"
}
 
{
Date d1 = date("2 November 2010")
print intOf d1
}
 

Re: Date comparison logic inverted?
Tony_Goodman - Fri Mar 28 10:53:50 EDT 2014

MyDeveloerWorks - Fri Mar 28 06:13:56 EDT 2014

Sorry to be opening this topic again, but I tried running the commands above recommended by Mathias and the results were still inverted.

When I appended Louies code I go errors:

-E- DXL: <Line:17> incorrect arguments for function (null)

I have a Spanish PC and tested on  DOORS 8.3 and 9.5.2

I had to modify it as follows to get it to work

{
Date d1 = date("2-11-2010",userLocale, "dd-MM-yyyy")
Date d2 = date("3-11-2010",userLocale, "dd-MM-yyyy")
 
print (d1 == d2) "\n"
print (d1 != d2) "\n"
print (d1 < d2) "\n"
print (d1 > d2) "\n"
print (d1 <= d2) "\n"
print (d1 >= d2) "\n"
}
 
{
Date d1 = date("2 November 2010")
print intOf d1
}
 

Just a hunch, but if you are on a Spanish machine, try using "Noviembre" instead of "November"

Re: Date comparison logic inverted?
llandale - Fri Mar 28 12:00:31 EDT 2014

Tony_Goodman - Fri Mar 28 10:53:50 EDT 2014

Just a hunch, but if you are on a Spanish machine, try using "Noviembre" instead of "November"

That is, the date() function is returning null because it ..err.. your Locale doesn't understand the string date format you are using.  easily enough checked, just print the dates after calculating them.

Re: Date comparison logic inverted?
MyDeveloerWorks - Fri Mar 28 13:01:44 EDT 2014

llandale - Fri Mar 28 12:00:31 EDT 2014

That is, the date() function is returning null because it ..err.. your Locale doesn't understand the string date format you are using.  easily enough checked, just print the dates after calculating them.

Hi Tony, Louie,

thanks for the responses,,, I am not at my DOORS desktop now so I will answer as best I can.

Regarding the language, there is more to the syntax (11 de noviembre de 2014).

I printed the dates after calculating them  and by trial and error I found that the format Date d1 = date("2-11-2010",userLocale, "dd-MM-yyyy") worked.

The real issue I am having and I have this opened in the General DOORS forum, is that my Locale conflicts with the the Locale chosen by the History Date attribute. Unless I force my Locale to conform to the one that that the Date Type in History uses, I cant get it to work.  

Re: Date comparison logic inverted?
llandale - Fri Mar 28 14:44:32 EDT 2014

MyDeveloerWorks - Fri Mar 28 13:01:44 EDT 2014

Hi Tony, Louie,

thanks for the responses,,, I am not at my DOORS desktop now so I will answer as best I can.

Regarding the language, there is more to the syntax (11 de noviembre de 2014).

I printed the dates after calculating them  and by trial and error I found that the format Date d1 = date("2-11-2010",userLocale, "dd-MM-yyyy") worked.

The real issue I am having and I have this opened in the General DOORS forum, is that my Locale conflicts with the the Locale chosen by the History Date attribute. Unless I force my Locale to conform to the one that that the Date Type in History uses, I cant get it to work.  

Over my head here, but I would suppose the following would not care one iota about "Locales"

  • Date datHist = hst.date   // This, I think, keeps the "date" pure

The following I suppose WOULD cause Locale issues:

  • string sDate = hst.date  // This, I think, converts to a string based on Locale
  • Date datHist = sDate

-Louie