System Date/Time Format Problems

J. Landman Gay jacque at hyperactivesw.com
Sat Jul 2 23:15:46 EDT 2011


On 7/2/11 2:46 PM, Pete wrote:

> So if a user tells me he wants his dates in OS X medium or long format, I
> can't find out what that is with LC code, same for an OS X long time.

Start with these. The functions below will only work on US systems, or 
in countries that use US date/time formats. If you want to accomodate 
other countries you'll have to do more work.

The "lookupZone" function is for the long and full time formats. I have 
exactly one entry in there for central time. What you need to do for 
that is make a list of all the time zones, one per line, in the same 
order my example uses. Store it in a custom property or somewhere. 
Retrieve the list for the lookup function.

There may be a shell call to do that, or a list stored somewhere in OS 
X. I don't know. Anyway, maybe this will get you started:

function formatDate pDate,pFormat -- short, medium, long, full
   switch pFormat
     case "short"
       convert pDate to short date
       put pDate into tFormattedDate
       break
     case "medium"
       convert pDate to abbrev date
       put item 2 to -1 of pDate into tFormattedDate
       break
     case "long"
       convert pDate to long date
       put item 2 to -1 of pDate into tFormattedDate
       break
     case "full"
       convert pDate to long date
       put pDate into tFormattedDate
       break
   end switch
   return tFormattedDate
end formatDate

function formatTime pTime,pFormat
   switch pFormat
     case "short"
       convert pTime to short time
       put pTime into tFormattedTime
       break
     case "medium"
       convert pTime to long time
       put pTime into tFormattedTime
       break
     case "long"
     case "full"
       convert pTime to long time
       put pTime into tFormattedTime
       convert pTime to internet date
       put word 6 of pTime into tTimeZone
       put lookupZone(tTimeZone) into tZoneInfo
       if pFormat = "long" then
         put item 2 of tZoneInfo into tTimeZone
       else -- full
         put item 3 of tZoneInfo into tTimeZone
       end if
       put space & tTimeZone after tFormattedTime
       break
   end switch
   return tFormattedTime
end formatTime

function lookupZone pHourOffset
   -- need a list in this format, one line per zone:
   put "-0500,CST,CT" into tZones
   return line lineoffset(pHourOffset,tZones) of tZones
end lookupZone

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list