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: FourthWorld, heatherlaine, Klaus, kevinmiller

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

dateitems strangness

Post by jawall » Thu Feb 27, 2014 7:56 pm

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

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

Re: dateitems strangness

Post by BvG » Thu Feb 27, 2014 8:14 pm

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

Post by jawall » Thu Feb 27, 2014 9:05 pm

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
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: dateitems strangness

Post by BvG » Fri Feb 28, 2014 1:22 am

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
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: dateitems strangness

Post by dunbarx » Fri Feb 28, 2014 1:36 am

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
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

Post by jawall » Fri Feb 28, 2014 6:48 am

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
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: dateitems strangness

Post by BvG » Fri Feb 28, 2014 1:59 pm

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”