dateitems strangness

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

jawall
Posts: 31
Joined: Wed Sep 12, 2012 1:43 pm

dateitems strangness

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

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
Anybody?
Thank you!
Jürgen

BvG
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: dateitems strangness

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".
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

jawall
Posts: 31
Joined: Wed Sep 12, 2012 1:43 pm

Re: dateitems strangness

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

BvG
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: dateitems strangness

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
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

dunbarx
VIP Livecode Opensource Backer
Posts: 6921
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: dateitems strangness

What Bjoernke said.

DateItems produces a comma delimited string. Nothing more. You cannot do math on that at all, as, for example:

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
end mouseUp``````
Yipes!

Craig
Last edited by dunbarx on Fri Feb 28, 2014 7:18 am, edited 1 time in total.

jawall
Posts: 31
Joined: Wed Sep 12, 2012 1:43 pm

Re: dateitems strangness

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

Code: Select all

``add 365 to  someDateAsDateItem``
results in an error and thus cannot be a number

Thank you both for your assistance in understanding and solving
Jürgen

BvG
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: dateitems strangness

Great that it works for you now!

We all learn in small steps
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode