Date Calculation

Mike Kerner MikeKerner at roadrunner.com
Thu Nov 29 16:23:57 EST 2012


Just as an intellectual exercise I worked on shortening the script up
because the only way to fix the case is to add a bunch of breaks to it or
change the conditionals and order.  If you want to shorten it, here's one
option:

*function* DetermineWeek pDate

   *if* pDate is empty *then*

      *put* the date into pDate

   *end* *if* *# pDate is empty*

   *convert* pDate to dateItems

   *put* item -1 of pDate into dayNumber

   *if* dayNumber=1 *then* *# Sunday, move to previous week*

      theOffset=6

   *else* *# Monday to Saturday*

      theOffset=dayNumber-2

   *end* *if* *# dayNumber=1*

   *subtract* theOffset from item 3 of pDate

   *convert* pDate to date

   *return* pDate

*end* DetermineWeek



More information about the use-livecode mailing list