Topic
  • 12 replies
  • Latest Post - ‏2014-03-28T18:44:32Z by llandale
LIMoon
LIMoon
3 Posts

Pinned topic Date comparison logic inverted?

‏2011-01-24T00:04:07Z |
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.
Updated on 2011-01-25T14:32:58Z at 2011-01-25T14:32:58Z by llandale
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: Date comparison logic inverted?

    ‏2011-01-24T00:21:27Z  

    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

     

     

    Updated on 2013-12-20T19:37:31Z at 2013-12-20T19:37:31Z by JAntley
  • PDU
    PDU
    139 Posts

    Re: Date comparison logic inverted?

    ‏2011-01-24T07:01:41Z  

    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.
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">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 </pre>

     


    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"
    

     

    Updated on 2013-12-20T19:39:11Z at 2013-12-20T19:39:11Z by JAntley
  • Mathias Mamsch
    Mathias Mamsch
    2159 Posts

    Re: Date comparison logic inverted?

    ‏2011-01-24T12:55:30Z  

    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

     

     

    Updated on 2013-12-20T19:39:47Z at 2013-12-20T19:39:47Z by JAntley
  • llandale
    llandale
    3035 Posts

    Re: Date comparison logic inverted?

    ‏2011-01-24T22:35:44Z  
    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
  • LIMoon
    LIMoon
    3 Posts

    Re: Date comparison logic inverted?

    ‏2011-01-25T10:15:16Z  
    • PDU
    • ‏2011-01-24T07:01:41Z

    Hello,

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

    I try with 9.1 and french PC.

    With :

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Date d1 = date("2 November 2010") Date d2 = date("3 November 2010") print "date=" d1 "\n" print "date=" d2 "\n" print (d1 == d2) "\n" </pre>

     


    I have :
    date=
    date=
    true

    With :

     

     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Date d1 = date("2/11/2010") Date d2 = date("3/11/2010") print "date=" d1 "\n" print "date=" d2 "\n" print (d1 == d2) "\n" </pre>



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

    And with :



     

     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">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" </pre>

     

    Thank you for the date formatting tip, Pierre.
  • LIMoon
    LIMoon
    3 Posts

    Re: Date comparison logic inverted?

    ‏2011-01-25T10:17:44Z  
    • LIMoon
    • ‏2011-01-25T10:15:16Z
    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!
  • llandale
    llandale
    3035 Posts

    Re: Date comparison logic inverted?

    ‏2011-01-25T14:32:58Z  
    • LIMoon
    • ‏2011-01-25T10:17:44Z
    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!
  • MyDeveloerWorks
    MyDeveloerWorks
    41 Posts

    Re: Date comparison logic inverted?

    ‏2014-03-28T10:13:56Z  

    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
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">{ 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 } </pre>

     

     


    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
    }
     
  • Tony_Goodman
    Tony_Goodman
    271 Posts

    Re: Date comparison logic inverted?

    ‏2014-03-28T14:53:50Z  

    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"

  • llandale
    llandale
    3035 Posts

    Re: Date comparison logic inverted?

    ‏2014-03-28T16:00:31Z  

    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.

  • MyDeveloerWorks
    MyDeveloerWorks
    41 Posts

    Re: Date comparison logic inverted?

    ‏2014-03-28T17:01:44Z  
    • llandale
    • ‏2014-03-28T16:00:31Z

    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.  

  • llandale
    llandale
    3035 Posts

    Re: Date comparison logic inverted?

    ‏2014-03-28T18:44:32Z  

    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