Page 1 of 1
dateitems strangness
Posted: Thu Feb 27, 2014 7:56 pm
by jawall
Hey there,
I am totally confused by this (I am working on a German system thus the dd.mm.yyyy format):
Code: Select all
set useSystemDate to true
put "04.11.2013" into d1
convert d1 to dateitems
put "20.11.2013" into d2
convert d2 to dateitems
answer (d1 < d2) -- the answer here is FALSE !!!!
Code: Select all
set useSystemDate to true
put "01.11.2014" into d1
convert d1 to dateitems
put "20.11.2014" into d2
convert d2 to dateitems
answer (d1 < d2) -- the answer here is TRUE !!!!
Anybody?
Thank you!
Jürgen
Re: dateitems strangness
Posted: Thu Feb 27, 2014 8:14 pm
by BvG
the problem is that dateitems is not really a number, so comparing them like a number can have weird results. In your examples, the actual compared numbers look like this. I haven't completely tested it, but I bolded them to show what I think is happening:
2013,11,4,0,0,0,2 -- this is bigger
2013,11,20,0,0,0,4
2014,11,1,0,0,0,7
2014,11,20,0,0,0,5 -- this is bigger
To avoid the problem I suggest you convert to "the seconds" instead of "the dateitems".
Re: dateitems strangness
Posted: Thu Feb 27, 2014 9:05 pm
by jawall
Thanks BvG,
converting to seconds - as you suggested - solves the problem.
It, on the other hand, is still weird that the dateItems do not work as expected (and I think also described in the dictionary). It also is rather inconvenient in the environment that I need to do the date calculations in.
But I guess I'll have to stick to that workaround.
Jürgen
Re: dateitems strangness
Posted: Fri Feb 28, 2014 1:22 am
by BvG
Uhm where in the dictionary or other documentation does it say that dateitems is a good format to do math comparision with? If that's in there it needs to be fixed!
remember that you can always convert from seconds to dateitems, after comparing them, if that is what you need, for example:
on mouseUp
put the seconds into todayCompare
repeat for each line theLine in theListOfDatesInSeconds
if theLine < todayCompare then
convert theLine from seconds to dateItems
put theLine & return after theListOfFuture
else
convert theLine from seconds to dateItems
put theLine & return after theListOfPast
end if
end repeat
put theListOfPast
end mouseUp
Re: dateitems strangness
Posted: Fri Feb 28, 2014 1:36 am
by dunbarx
What Bjoernke said.
DateItems produces a comma delimited string. Nothing more. You cannot do math on that at all, as, for example:
add 3 to "1,2,3"
That dog don't hunt.
On the other hand, LC is simply adorable in that you can do something like this:
Code: Select all
on mouseUp
get the date
convert it to dateItems
add 100 to item 3 of it
convert it to date
answer it
end mouseUp
Yipes!
Craig
Re: dateitems strangness
Posted: Fri Feb 28, 2014 6:48 am
by jawall
Yes, Carig and Bjornke, you are both right. I can't second my first impression that dateitems are suggested for calculations in the dictionary.The source of information I had in mind is this
http://revolution.byu.edu/time/timeInRev.php (in the lower third of the page)
The thing is that date items
suggests they are perfect for date calculation because - as Craig pointed out -
Code: Select all
add 365 to item 3 of someDateAsDateItem
produces proper date (after further reconverting).
Thinking logically, I could have guessed that it is not helpful to compare two dateitems entities because
results in an error and thus cannot be a number
Thank you both for your assistance in understanding and solving
Jürgen
Re: dateitems strangness
Posted: Fri Feb 28, 2014 1:59 pm
by BvG
Great that it works for you now!
We all learn in small steps
