time shorthand convertor

Jim Ault JimAultWins at yahoo.com
Thu Jul 27 17:12:08 EDT 2006


Yeah, its fun to have many ways to do the same job :-)


On 7/27/06 1:36 PM, "Josh Mellicker" <josh at dvcreators.net> wrote:

> Wow, thanks Jim, a nice improvement!
> 
> On Jul 27, 2006, at 12:23 PM, Jim Ault wrote:
> 
>> A different approach to get to the same point....
>> ... added error checking for invalid time strings
>> 
>> ON convertTime
>>   put the text of the target into str
>> 
>>   repeat for each char CH in str
>>     if CH is a number then put CH after timeStr
>>   end repeat
>>   put " 00" after timeStr
>>   get char -4 to -3 of word 1 of timeStr & " " &  \
>>        char -2 to -1  of word 1 timeStr && word -1 of timeStr
>>   put word 1 to 2 of it into timeStr
>>   replace space with ":" in timeStr
>> 
>>   if str contains "a" then put " AM" after timeStr
>>   else put " PM" after timeStr
>>   --now let's error check --------------------------
>>   get timeStr
>>   convert it to seconds
>>   if it = timeStr then  --no conversion was done
>>     answer "oops.. "& str & " does not look like a time"
>>     exit to top
>>   else
>>     ---- looks good -----------------------------------------
>>     --so we will publish the result
>>     set the twelvehourtime to true
>>     convert it to short time
>>     put it into target
>>   end if
>> END convertTime
>> 
>> 
>> 
>> On 7/27/06 11:06 AM, "Josh Mellicker" <josh at dvcreators.net> wrote:
>> 
>>> Here is an interesting handler so that a user can enter a time in a
>>> field in a "shorthand" and get a full, properly formatted date out of
>>> it.
>>> 
>>> Here are some examples:
>>> 
>>> enter this = get this
>>> 
>>> 1 = 1:00 PM
>>> 12 = 12:00 PM
>>> 123 = 1:23 PM
>>> 1234 = 12:34 PM
>>> 
>>> add an "a" at the end for am, like:
>>> 
>>> 1a = 1:00 AM
>>> 
>>> We have been using this for a few days and everyone really likes it,
>>> it seems intuitive and faster than any other method of entering a
>>> time.
>>> 
>>> 
>>> 
>>> field script:
>>> 
>>>      ON enterInField
>>>          convertTime
>>>      END enterInField
>>> 
>>>      ON returnInField
>>>          convertTime
>>>      END returnInField
>>> 
>>>      ON closeField
>>>          convertTime
>>>      END closeField
>>> 
>>> 
>>> put this somewhere in the message path:
>>> 
>>>      ON convertTime
>>>          put the text of the target into t
>>>          IF (char -1 to -2 of t = "am") OR (char -1 of t = "a") THEN
>>>              put "AM" into ampm
>>>          ELSE
>>>              put "PM" into ampm
>>>          END IF
>>>          REPEAT for each char c in t
>>>              IF c is a number THEN put c after t2
>>>          END REPEAT
>>> 
>>>          SWITCH
>>>          CASE the number of chars of t2 < 3
>>>              put ":00" after t2
>>>              break
>>>          CASE the number of chars of t2 = 3
>>>              put char 1 of t2 & ":" & char 2 to 3 of t2 into t2
>>>              break
>>>          CASE the number of chars of t2 = 4
>>>              put char 1 to 2 of t2 & ":" & char 3 to 4 of t2 into t2
>>>              break
>>>          END SWITCH
>>>          put space & ampm after t2
>>>          put t2 into the target
>>>      END convertTime
>>> _______________________________________________
>>> use-revolution mailing list
>>> use-revolution at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription
>>> preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>> 
>> 
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the Use-livecode mailing list