a little more on datetime

Jim Ault JimAultWins at yahoo.com
Mon Dec 19 02:51:02 EST 2005


On 12/18/05 5:29 PM, "Timothy Miller" <gandalf at doctorTimothyMiller.com>
wrote: <excerpted>
> As Jacque recently mentioned, RR is inconsistent in the way it copes
> with dates and times, when interpreting, sorting or converting
> values. How true!
> The IDE seems to be making these determinations anyway, but not reporting
> them
> <major snip>  (the full quote below)
Caution:  You are making assumptions about what 'convert' is working with
for a short date string.  As with any programming language, functions are
designed with limitations and tend to be 'GIGO' ( garbage in....).  In
particular, date and time functions in any program I have ever worked with
are an adventure in hitting sweet spots, and, boy, are they all different!

Try the following script and see what the nuances are.  Pay attention to
what Rev generates as the short date, and then the converted values.

The final answer is that Rev gives you the tools to generate a
"cleanShortDate()" function to hand off to 'convert', much like the 'trim'
functions discussed over the last few weeks.

By the way... you used...
> The result is still empty.
What you need --->  look in "it", not the result (according to the docs and
my example)

------------- code to copy starts here
on mousedoubleUp
  put "      11/24/96" into var1
  answer (var1 is a date) &cr& "var1 could be a date of some sort."
  convert var1 to long date
  --convert var1 to seconds
  answer var1 &cr&" convert var1 to long date = " & it &", Rev did it"
  answer var1 &cr&" convert var1 to long date = " & it \
  &cr& "whooops.. now why did that happen?? " &cr& "11/24/96 > Dec 31st ?"

  convert var1 to short date
  answer var1 &cr&" convert var1 to short date = " & it &", Rev did it"
&cr&"Yuk"
  convert var1 to seconds
  answer var1 &cr& " convert var1 to seconds = " & it &", Rev did it"
&cr&"Double Yuk"

  convert "11/24/96" to seconds
  answer "11/24/96  >" & it &cr&"starting clean"
  
  convert "11/24/9" to seconds
  answer "11/24/9  >" & it &cr&"one char shorter"
  
  convert "11/24/" to seconds
  answer "11/24/  >" & it &cr&"two chars shorter gets worse, but there is a
pattern"
  --considering short date -- prefix padded with spaces
  put "11/24/96" into var2
  put "" into resultList
  put var2 into original
  repeat with x = 1 to 10
    put " " before var2
    get var2
    convert it to short date
    put x & "-space prefix [date]= " & it into line x of resultList
  end repeat
  convert original to  short date
  put "0-space prefix [date]= " & original &cr before resultList
  put cr & "**watch the *year* on each line" after resultList
  answer resultList
  --considering seconds -- prefix padded with spaces
  put "11/24/96" into var3
  put "" into resultList
  put var3 into original
  repeat with x = 1 to 10
    put " " before var3
    get var3
    convert it to seconds
    put x & "-space prefix [secs]= " & it into line x of resultList
  end repeat
  convert original to seconds
  put "0-space prefix [secs]= " & original &cr before resultList
  answer resultList
  --considering a suffix padded with spaces
  put "11/24/96" into var4
  put "" into resultList
  repeat with x = 1 to 10
    put " " after var4
    get var4
    convert it to seconds
    put x & "-space suffix = " & it into line x of resultList
  end repeat
  answer resultList
  answer "Moral: At first, First dates can be deceiving"
  
end mousedoubleUp


---------------- end code to copy

On 12/18/05 5:29 PM, "Timothy Miller" <gandalf at doctorTimothyMiller.com>
wrote:

> Greetings,
> 
> As Jacque recently mentioned, RR is inconsistent in the way it copes
> with dates and times, when interpreting, sorting or converting
> values. How true!
> 
> As far as I can tell, the IDE will appear to sort datetime or convert
> from one dateTime format to another, without producing an error
> message, regardless of the value in question. It will do so in cases
> where the value is almost, but not quite completely unlike a date or
> a time. If the IDE cannot understand the value as a date or time, it
> sorts as if the value were alphanumeric, or ignores the convert
> command.
> 
> In addition, it will report a value is a date, but then refuse to
> recognize the same value as a date when converting or sorting.
> 
> Try this:
> 
> on mouseUp
>    put "      11/24/96" into var1
>    answer (var1 is a date)
>    convert var1 to seconds
>    answer the result
>    answer var1
> end mouseUp
> 
> At least on my machine and version, the IDE reports the value is a
> date, but then refuses to convert it, or converts it incorrectly. The
> result is empty.
> 
> This example even stranger:
> 
> on mouseUp
>    put "         11/24/96" & cr & "avfdt" into var1
>    answer (var1 is a date)
>    convert var1 to seconds
>    answer the result
>    answer var1
> end mouseUp
> 
> 
> The IDE says the value in the second example is also a number, but it
> ignores the same leading spaces AND the second line, AND correctly
> converts the first line, leading spaces and all, to seconds! The
> result is still empty.
> 
> The second example suggests a handy hack if you want to force the IDE
> to correctly interpret certain badly formatted dates or times. Just
> ad a cr and some nonsense characters in the second line. I'm mostly
> joking...
> 
> Maybe this is all as it must be, for obscure reasons. Still, it seems
> to me the user needs a break here. A small and likely easy step would
> be for the IDE to give the user a result, if the user cares to take
> advantage of it. "Ambiguous dateTime value" other such words might be
> helpful in some cases. "Value not in dateTime format" and "value
> contains multiple lines" are other possibilities.
> 
> The IDE seems to be making these determinations anyway, but not reporting
> them.
> 
> Is this is a bad idea?
> Tim





More information about the use-livecode mailing list