sneak-peek: calendar object

Shao Sean shaosean at
Sun Mar 17 19:52:00 EST 2002

> Just out of curiosity, are you using system calls or decyphering
> known dates converted using the long system date function?
originally i had a few functions and handlers that figured out all my
months/years based off of today's date (kinda right really).. the only
problem with it was everything had to start at sunday, english only, and
lots more room for errors.. the good thing about doing it this way was the
fact that there was beginning and/or end for my getting dates (could go all
the way back to january 1AD if i wanted)

i ended up taking a look through the transcript dictionary, and for some
reason took a look at the "convert" function (remember seeing it in an
earlier thread).. now my code uses the "convert" function and "the seconds"
to get all the date/month/year information.. this way works a lot better
because i can handle non-english date information as well as displaying the
information in the language setting that is set in the user's computer
(dutch is cool).. the only down fall i've seen to this is the date
information has a starting date of something back in 1970 (someone correct
me if i'm work.. i usually do my reading and coding at 2 in the morning
after getting off of work)..

here's what i use to do my date information:

(put it in a button and give it a try)
on mouseUp
  local vDateItems
  # this will convert the seconds into the dateItems for today
  # look up "convert" to see what dateItems are.. it's handy
  # dateItems are in the format of YYYY,MM,DD,HH,MM,SS,DayOfWeek
  # where, HH is 24hour and DayOfWeek is an number (1=sunday, 7=saturday)
  convert the seconds to dateItems
  put it into vDateItems
  # vDateItems now contains 2002,3,17,19,38,24,1
  # so now we have today, let's move back a national holiday for my country
  # canada day is july 1st so let's go see what day of the week that falls
  put 7 into item 2 of vDateItems  -- july
  put 1 into item 3 of vDateItems  -- first
  # i like to wipe out the time information, but it's not really that
  # uncomment the following lines if you want it wiped out
  -- put 0 into item 4 of vDateItems  -- wipe out hours
  -- put 0 into item 5 of vDateItems  -- wipe out minutes
  -- put 0 into item 6 of vDateItems  -- wipe out seconds
  # so now vDateItems contains 2002,7,1,0,0,0,1
  # the day of the week containedin vDateItems may or may not be correct
  # but that's okay, because it'll get corrected in the next two lines
  convert vDateItems from dateItems to seconds  -- convert back to seconds
  # the above conversion automatically does the conversion and places
  # it back in the vDateItems variable
  convert vDateItems from seconds to dateItems  -- convert back to dateItems
  # now vDateItems contains the date information for july 1st, 2002
  # vDates now contains 2002,7,1,0,0,0,2
  # so canada day this year falls on a monday
  put vDateItems
end mouseUp

> I already have a handler that can decypher the short date format from
> the long system date.  Now I realize I can capture day and month
> names using the same technique.
the techniques i switched to to get the dayOfWeek and month names (in the
current system language) is as follows:

"weekdayNames" (look it up)
example: put the abbr system weekdayNames in vWeekdayNames
returns a linefeed delimited list containing the names of the weekdays
(sunday, monday, etc) in the language setting used by the system

example: put the system monthNames in vMonthNames
returns a linefeed delimited list containing the names of the months in the
language setting used by the system

hope that helps someone out with something..

More information about the use-livecode mailing list