Week Math

A fun holiday challenge: There are 52 weeks in a year.  A colleague of mine is taking a date and converting it to a week number using some complex JavaScript example they found on the internet and I feel there has to be a good way to do it with the date functions in PilotScript.  I would love to have two functions that, assuming a week runs Monday to Sunday, that:

  1. Take a date and return a number from 1 - 52 (or 53!) representing which week of the year it is in.
  2. Take a year and week number and return a start date for the Monday of the week 
  3. Extra credit, for both functions above allow specifying whether the start date is a Sunday or Monday since not everyone follows the ISO standards as described in