Comparing Links by "Created On" attribute

Hi All,
I'm trying to create a DXL layout column by modifying the Analysis Wizard script that I generated simply by following outlinks and selecting the "Created On" attribute of the links for display.
I modified the script by adding a string (s2 below) to use for comparing against the "Created On" dates. What I'm trying to do is have only those dates older than Wednesday, September 15, 2010 display in the DXL column, but for some reason ALL dates are being displayed, including more recent dates. What is wrong with the modified script below? I only added the "if (s<s2)" line because the DOORS DXL help files show that this can be done in this fashion. HELP!!

// DXL generated by DOORS traceability wizard on 17 September 2010.
// Wizard version 2.0, DOORS version 8.3.0.1
pragma runLim, 0
void showOut(Object o, int depth) {
Link l
LinkRef lr
ModName_ otherMod = null
Module linkMod = null
ModuleVersion otherVersion = null
Object othero
string disp = null
string s = null
string s2 = "Wednesday, September 15, 2010"
string plain, plainDisp
int plainTextLen
int count
bool doneOne = false
string linkModName = "*"
for l in all(o->linkModName) do {
otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) continue
othero = target l
if (null othero) {
load(otherVersion,false)
}
othero = target l
if (null othero) continue
if (isDeleted othero) continue
doneOne = true
if (depth == 1) {
if (canRead(l."Created On")) s = probeAttr_(l, "Created On" )
else s = ""
//Trying to get DXL column to only display links older than a certain date, defined by s2
if (s<s2)
s = ""
if (s == "")
displayRich("\\pard " " ")
else
displayRich("\\pard " s)

}
}
}
showOut(obj,1)
ChrisAnnal - Fri Sep 17 16:39:49 EDT 2010

Re: Comparing Links by "Created On" attribute
SystemAdmin - Fri Sep 17 17:17:52 EDT 2010

You may want to try comparing date types by casting the string into a date, rather than using strings.

For example:
Date s1
Date s2 = "9/15/10 10:00:00"

s1 = s
if(s1<s2) http://...

Then when printing via the Wizard-created function, make sure you convert back to a string (if required) for displayRich, as it's looking for a string. You may simply pass s, if you've preserved it.

Re: Comparing Links by "Created On" attribute
SystemAdmin - Fri Sep 17 17:19:53 EDT 2010

SystemAdmin - Fri Sep 17 17:17:52 EDT 2010
You may want to try comparing date types by casting the string into a date, rather than using strings.

For example:
Date s1
Date s2 = "9/15/10 10:00:00"

s1 = s
if(s1<s2) http://...

Then when printing via the Wizard-created function, make sure you convert back to a string (if required) for displayRich, as it's looking for a string. You may simply pass s, if you've preserved it.

Sorry about the http address in there, didn't think to add the code brackets before posting, and it decided to markup for me - please ignore!

Teach me to post without a preview...

Re: Comparing Links by "Created On" attribute
ChrisAnnal - Fri Sep 17 19:00:44 EDT 2010

Unfortunately, there is apparently a difference in the date format that the string is being cast into. Here's how I tried to apply the script (this was checked as "no errors" by the DXL checker in DOORS)

// DXL generated by DOORS traceability wizard on 17 September 2010.
// Wizard version 2.0, DOORS version 8.3.0.1
pragma runLim, 0
void showOut(Object o, int depth) {
Link l
LinkRef lr
ModName_ otherMod = null
Module linkMod = null
ModuleVersion otherVersion = null
Object othero
string disp = null
string s = null

Date d1
Date d2

string plain, plainDisp
int plainTextLen
int count
bool doneOne = false
string linkModName = "*"
for l in all(o->linkModName) do {
otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) continue
othero = target l
if (null othero) {
load(otherVersion,false)
}
othero = target l
if (null othero) continue
if (isDeleted othero) continue
doneOne = true
if (depth == 1) {
if (canRead(l."Created On")) s = probeAttr_(l, "Created On" )
else s = ""
string s2 = "Wednesday, September 15, 2010"
d1 = s
d2 = s2
if (d1<d2)
s = ""
if (s == "")
displayRich("\\pard " " ")
else
displayRich("\\pard " s)

}
}
}
showOut(obj,1)

Unfortunately, this produced the following error (Line 38 is where I'm casting "d1 = s")

-R-E- DXL: <Line:38> incorrect format or value for date (Thursday, March 11, 2010)
Backtrace:
<Line:50>
-I- DXL: execution halted

I've tried variations like using "stringOf" and trying to make the formats more compatible buy using "dateOnly(Date d1)", but still haven't found the secret recipe

Re: Comparing Links by "Created On" attribute
ostanescu - Mon Sep 20 15:48:28 EDT 2010

ChrisAnnal - Fri Sep 17 19:00:44 EDT 2010
Unfortunately, there is apparently a difference in the date format that the string is being cast into. Here's how I tried to apply the script (this was checked as "no errors" by the DXL checker in DOORS)

// DXL generated by DOORS traceability wizard on 17 September 2010.
// Wizard version 2.0, DOORS version 8.3.0.1
pragma runLim, 0
void showOut(Object o, int depth) {
Link l
LinkRef lr
ModName_ otherMod = null
Module linkMod = null
ModuleVersion otherVersion = null
Object othero
string disp = null
string s = null

Date d1
Date d2

string plain, plainDisp
int plainTextLen
int count
bool doneOne = false
string linkModName = "*"
for l in all(o->linkModName) do {
otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) continue
othero = target l
if (null othero) {
load(otherVersion,false)
}
othero = target l
if (null othero) continue
if (isDeleted othero) continue
doneOne = true
if (depth == 1) {
if (canRead(l."Created On")) s = probeAttr_(l, "Created On" )
else s = ""
string s2 = "Wednesday, September 15, 2010"
d1 = s
d2 = s2
if (d1<d2)
s = ""
if (s == "")
displayRich("\\pard " " ")
else
displayRich("\\pard " s)

}
}
}
showOut(obj,1)

Unfortunately, this produced the following error (Line 38 is where I'm casting "d1 = s")

-R-E- DXL: <Line:38> incorrect format or value for date (Thursday, March 11, 2010)
Backtrace:
<Line:50>
-I- DXL: execution halted

I've tried variations like using "stringOf" and trying to make the formats more compatible buy using "dateOnly(Date d1)", but still haven't found the secret recipe

Hi,
You are getting the date attribute value into a string, why not:

if (canRead(l."Created On")) {
   d1 = l."Created On"
   s = stringOf d1
}
else 
  s = ""
 
Date d2 = "09/15/2010"
 
if (d1 < d2)
  s = ""
 
if(s == "") 
  displayRich("\\pard " " ")
else
  displayRich("\\pard " s)

Re: Comparing Links by "Created On" attribute
Mathias Mamsch - Tue Sep 21 02:49:25 EDT 2010

ostanescu - Mon Sep 20 15:48:28 EDT 2010

Hi,
You are getting the date attribute value into a string, why not:

if (canRead(l."Created On")) {
   d1 = l."Created On"
   s = stringOf d1
}
else 
  s = ""
 
Date d2 = "09/15/2010"
 
if (d1 < d2)
  s = ""
 
if(s == "") 
  displayRich("\\pard " " ")
else
  displayRich("\\pard " s)

When converting date values to strings and vice versa you should always think about using locales. Remember that casting a date to string will always yield a string with a format that depends on the current userlocale.

So what i usually do is:

Date d = dateAndTime today() 
   // now we can be sure of the format of the string
   string s = stringOf (d, "yy/MM/dd -")
   print "Date as String: " s "\n"
 
   Date d2 = date (s, "yy/MM/dd -") 
 
   // convert to another format
   print stringOf (d2, "ddd, dd MMM yyyy -")

 

 


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