VisualCalc logo

VisualCalc

Mathematics in your hand

Simple calendar

The US "Big six" holidays are:

yr = 2009
holidays = rep(date(1,1,1), 6)
holidays(1) = date(yr, 1, 1)     # New Years Day
holidays(2) = ndow(yr, 5, 5, 1)  # Memorial Day
holidays(3) = date(yr, 7, 4)     # Independence Day
holidays(4) = ndow(yr, 9, 1, 1)  # Labor Day
holidays(5) = ndow(yr, 11, 4, 4) # Thanksgiving
holidays(6) = date(yr, 12, 25)   # Christmas day

To check whether the given date is a holiday or not write the following:

d = date(2009, 12, 25)
if (size(find(holidays == d)))
  # it is a holiday
else
  # a regular day
end

Simple calendar for the Pro version

In the VisualCalc Pro the simple calendar may be converted to a function and stored in a library.

#simple calendar
holidays = rep(date(1,1,1), 6)

func make_holidays(yr)
  if (year(.holidays(1)) == yr)
    ret
  end
  .holidays(1) = date(yr, 1, 1)     # New Years Day
  .holidays(2) = ndow(yr, 5, 5, 1)  # Memorial Day
  .holidays(3) = date(yr, 7, 4)     # Independence Day
  .holidays(4) = ndow(yr, 9, 1, 1)  # Labor Day
  .holidays(5) = ndow(yr, 11, 4, 4) # Thanksgiving
  .holidays(6) = date(yr, 12, 25)   # Christmas day
end

func isholiday(d)
  make_holidays(year(d))
  if (size(find(.holidays == d)))
    ret(1)
  end
  ret(0)
end

To use the calendar you need to include it into the current expression:

use('simple calendar')
d = date(2009, 12, 25)
if (isholiday(d))
  # it is a holiday
else
  # a regular day
end

Checking for a weekend

Let's add check for a weekend to the calendar:

d = date(2009, 12, 25)
if (dow(d) >= 6 or size(find(holidays == d)))
  # holiday
else
  # working day
end

For the Pro version we need to rewrite the function isholiday:

func isholiday(d)
  make_holidays(year(d))
  if (dow(d) >= 6 or size(find(.holidays == d)))
    ret(1)
  end
  ret(0)
end