2012-06-15 40 views

回答

1
static date dateOfEaster(Yr y) 
{ 
    int a = y mod 19; 
    int b = y div 100; 
    int c = y mod 100; 
    int d = b div 4; 
    int e = b mod 4; 
    int f = (b+8) div 25; 
    int g = (b-f+1) div 3; 
    int h = (19*a+b-d-g+15) mod 30; 
    int i = c div 4; 
    int k = c mod 4; 
    int l = (32+2*e+2*i-h-k) mod 7; 
    int m = (a+11*h+22*l) div 451; 
    int n = (h+l-7*m+114) div 31; 
    int p = (h+l-7*m+114) mod 31; 
    return mkdate(p+1,n,y); 
} 
+0

僅限天主教復活節和格里曆! –

+1

那是你的頭腦? – sp00m

+0

不,我13年前在某處找到的舊代碼,並被X ++採用。你會在這裏找到一個相同的:http://stackoverflow.com/a/2192688/4509 –

1

我有一個小的創意,所以你可以枚舉所有假期使用GET與公共Web服務,一點點遞推某一年。隨你喜歡玩這個。只需複製/粘貼到作業:

static void HolidayWebService(Args _args) 
{ 
    System.Net.WebClient webClient = new System.Net.WebClient(); 
    str holidaysAvailable = "http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx/GetHolidaysAvailable?countryCode=UnitedStates"; 
    str holidayDate   = "http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx/GetHolidayDate?countryCode=%1&holidayCode=%2&year=%3"; 
    str retVal    = webClient.DownloadString(holidaysAvailable); 


    XMLDocument doc=XMLDocument::newXml(retVal); 
    XmlNamedNodemap  attributes; 
    XmlElement   root = doc.root(); 
    XmlNode    node = root.firstChild(); 


    void getHolidayDate(str _holidayCode, Yr _yr = datetimeutil::year(datetimeutil::utcNow()), str _countryCode = 'UnitedStates') 
    { 
     System.Net.WebClient webClientInner = new System.Net.WebClient(); 
     str locRetVal; 
     ; 

     try 
     { 

      locRetVal = webClientInner.DownloadString(strfmt(holidayDate, _countryCode, _holidayCode, _yr)); 

      info(strfmt("[%1] %2", _holidayCode, locRetVal)); 

     } 
     catch 
     { 
      error(strfmt("Error with %1, %2, %3", _holidayCode, _yr, _countryCode)); 
      continue; 
     } 
    } 

    void dig(XmlNode _node, int _depth = 0) 
    { 
     XmlNode sib; 
     ; 

     if (_node == null) 
      return; 

     if (_node.hasChildNodes()) 
      dig(_node.firstChild(), (_depth+1)); 
     else 
     { 
      if (_node.parentNode().name() == 'CODE') 
       getHolidayDate(_node.innerText()); 
     } 


     sib = _node.nextSibling(); 

     if (sib) 
      dig(sib); 
    } 
    ; 

    dig(node); 

} 
+1

+1讓別人努力工作! –

+0

我只希望他們的網絡服務不會崩潰:) –