Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

sword::HolidayRule Class Reference

A Holiday rule (used for building set of holidays). More...


Public Methods

 HolidayRule (const std::string &name, const std::string &rule)
 Parse the given 'rule' and keep the compiled version under the name 'name'.

std::string toString () const
 Creates a canonized string version of this rule.

bool compute (word year, Time &time) const
 Compute the actual date for this holiday within the given year.


Detailed Description

A Holiday rule (used for building set of holidays).

This is a holiday rule parser. You feed it with a textual description of a holiday, for example:

FR New year's day rule = "1 jan" FR Easter sunday rule = "easter_western" FR Easter monday rule = "1 mon after easter_western" US Memorial day rule = "1 mon before 1 jun" US Independance Day rule = "4 jul" US Independance Day (bis) rule = "1 after 4 jul if_sun" US Independance Day (ter) rule = "2 after 4 jul if_sat" GR Orthodox Easter monday rule = "1 mon after easter_orthodox from 1 jan 1994"

The exact grammar is as follows (pseudo BNF):

  rule
    : dayOfWeekOffset absoluteRule applicationRange?
    | dayOffset       absoluteRule applicationRange?
    |                 absoluteRule applicationRange?

  // '1 mon after'  : the newt monday
  // '3 tue before' : three tuesdays before
  dayOfWeekOffset
    : number dayOfWeek direction

  // '2 after' : two days after
  // '5 before' : five days before
  dayOffset
    : number direction

  absoluteRule
    : dayPosition year? dayOfWeekFilter?
    | special           dayOfWeekFilter?

  dayPosition
    : number month

  dayOfWeek
    : 'mon' | 'tue' .. | 'sun'

  direction
    : 'before' | 'after'

  month
    : 'jan' | 'fev' ... | 'dec'

  special
    : 'easter_western' | 'easter_orthodox' | 'vernal_equinox' | 'automnal_equinox'
    | 'winter_solstice' | 'summer_solstice' | 'chinese_newyear'

  year
    : number

  dayOfWeekFilter
    : 'if_mon' | 'if_tue' ... | 'if_sun'

  applicationrange
    : 'from' number month number
    | 'until 'number month number
  


Constructor & Destructor Documentation

sword::HolidayRule::HolidayRule const std::string &    name,
const std::string &    rule
 

Parse the given 'rule' and keep the compiled version under the name 'name'.


Member Function Documentation

bool sword::HolidayRule::compute word    year,
Time   time
const
 

Compute the actual date for this holiday within the given year.

If the method returns 'true', then a holiday exists according to this rule within the given year and the 'date' is set. If this method returns 'false', then there is no holiday this year according to this rule, and 'date' is left unchanged.

std::string sword::HolidayRule::toString   const
 

Creates a canonized string version of this rule.


Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2