Lasso Soft Inc. > Home

  • Articles

Holidays

Code for calculating U.S. holidays using Lasso's date tags.

Here is some code for calculating some common U.S. holidays using Lasso. The same methods can be used to calculate many other holidays. Holidays which are calculated on a lunar calendar like Easter require additional information so cannot be calculated like this.

Simple holidays like New Years Day are calculated with the fixed month, day, and the current year. More complex holidays like Memorial Day are calculated by counting to the proper day from a fixed point. Memorial Day is the last Monday in May so we start at May 31st and count back day by day until we find a Monday.

<?LassoScript
	
	// United States Holiday Calculations
	
	// The year set here is used in the later date calculations
	var('year') = date->year;
		
	// New Years Day, January 1st
	var('newyearsday') = date(-year=$year, -month=1, -day=1);

	// Memorial Day, Last Monday in May
	var('memorialday') = date(-year=$year, -month=5, -day=31);	
	while($memorialday->dayofweek != 2);
		$memorialday->subtract(-day=1);
	/while;

	// Independence Day, July 4th
	var('independenceday') = date(-year=$year, -month=7, -day=4);

	// Labor Day, First Monday in September
	var('laborday') = date(-year=$year, -month=9, -day=1);
	while($laborday->dayofweek != 2);
		$laborday->add(-day=1);
	/while;

	// Thanksgiving, Fourth Thursday in November
	var('thanksgiving') = date(-year=$year, -month=11, -day=22);	
	while($thanksgiving->dayofweek != 5);
		$thanksgiving->add(-day=1);
	/while;

	// Christmas Eve, December 24th
	var('christmaseve') = date(-year=$year, -month=12, -day=24);
	
	// Christmas, December 25th
	var('christmas') = date(-year=$year, -month=12, -day=25);
	
	// New Years Eve, December 31st
	var('newyearseve') = date(-year=$year, -month=12, -day=31);
?>

 

The holidays can be displayed by outputting the date using [Date->Format] or [Date_Format]. For example, the date of Thanksgiving could be output like this. The output for 2008 is shown.

This year Thanksgiving falls on [$thanksgiving->format('%Q')].
 This year Thanksgiving falls on 2008-11-27.

 

If several holidays are being output then it might be more efficient to use [Date_SetFormat]. The output for 2008 is shown.

[Date_SetFormat('%Q')]
This year Thanksgiving falls on [$thanksgiving] and Christmas falls on [$christmas].
 This year Thanksgiving falls on 2008-11-27 and Christmas falls on 2008-12-25.

Author: Fletcher Sandbeck
Created: 8 Apr 2008
Last Modified: 16 Mar 2011

Comments

No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft