pike.git / lib / modules / Calendar.pmod / Events.pmod

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Events.pmod:9:   constant month2n=(["Jan":1,"Feb":2,"Mar":3,"Apr":4,"May":5,"Jun":6,    "Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12]);   constant wd2n=(["Mon":1,"Tue":2,"Wed":3,"Thu":4,"Fri":5,"Sat":6,"Sun":7]);      void read_all_data()   {    all_data=master()->master_read_file(    combine_path(__FILE__,"../events/regional"));   }    +  + //! The Event system + //! + //! Q: How do I find out which days are red in a specific region? + //! + //! A: Events.<region> + //! + //! - contains the events for the region, as a SuperEvent. + //! You can ask this object to filter out the holidays, + //! + //! @code + //! Events.se.holidays(); + //! @endcode + //! + //! Which will be a superevent containing only holidays. + //! + //! To use this information, you can for instance use ->scan, + //! here in an example to see what red days there were in Sweden + //! in 2001 + //! + //! @code + //! > Calendar.Events.se->filter_flag("h")->scan(Calendar.Month()); + //! Result: ({ /* 6 elements */ + //! Day(Sun 7 Jan 2001), + //! Day(Sun 14 Jan 2001), + //! Day(Sun 21 Jan 2001), + //! Day(Sun 28 Jan 2001), + //! Day(Sat 6 Jan 2001), + //! Day(Mon 1 Jan 2001) + //! @endcode +    Event.Event make_event(string source)   {    string id;    string flags;    string s;    string rule;       if (sscanf(source, "%*[ \t]Event%*[ \t]"    "\"%[^\"]\"%*[ \t]%[-a-z]%*[ \t]"    "\"%s\"%*[ \t]%[^\n]",
pike.git/lib/modules/Calendar.pmod/Events.pmod:135:    n,days)>=2)    return Event.Easter_Relative(id,s,n);    error("Events: rule error; unknown rule format:\n%O\n",source);       case "Julian_Easter":    if (sscanf(rule,"Julian_Easter%*[ \t]%d%*[ \t]%d days",    n,days)>=2)    return Event.Easter_Relative(id,s,n);    error("Events: rule error; unknown rule format:\n%O\n",source);    +  case "Equinox": +  if (sscanf(rule, "Equinox%*[ \t]%s", string type)) { +  switch(String.trim_all_whites(type)) { +  case "Vernal": case "Northward": +  return Event.Solar(0); +  case "Autumnal": case "Southward": +  return Event.Solar(2); +  } +  } +  error("Events: rule error; unknown rule format:\n%O\n",source); +  +  case "Solstice": +  if (sscanf(rule, "Solstice%*[ \t]%s", string type)) { +  switch(String.trim_all_whites(type)) { +  case "Summer": case "Northern": +  return Event.Solar(1); +  case "Winter": case "Southern": +  return Event.Solar(3); +  } +  } +  error("Events: rule error; unknown rule format:\n%O\n",source); +     case "Weekday":    if (sscanf(rule,"Weekday%*[ \t]%s%*[ \t]%d days",    wd,days)>=2 && (n=wd2n[wd]))    return Event.Weekday(n,id);    error("Events: rule error; unknown rule format:\n%O\n",source);       case "Null":    return Event.NullEvent(id,s);       default:
pike.git/lib/modules/Calendar.pmod/Events.pmod:172:   }      mapping made_namedays=([]);      string read_all_namedays()   {    return master()->master_read_file(    combine_path(__FILE__,"../events/namedays"));   }    +    Event.Namedays find_namedays(string region)   {    string id="namedays/"+region;    object res;    if ( (res=made_namedays[region]) )    return res;    string all=read_all_namedays();       int i=search(all,"\nRegion \""+region+"\"");    if (i==-1) return UNDEFINED; // not found
pike.git/lib/modules/Calendar.pmod/Events.pmod:207: Inside #if 1
   switch (w=lower_case(w))    {    case "":    case "region": // ignore    break;    case "leapdayshift":    sscanf(s,"%d",leapdayshift);    break;    case "charset":    sscanf(s,"%s",charset); -  object dec=Locale.Charset.decoder(charset); +  object dec=Charset.decoder(charset);    decoder=lambda(string s)    {    return dec->feed(s)->drain();    };    break;    case "period":    if (names)    if (res)    res|=new_namedays_object(region,id,    start,stop,leapdayshift,names);
pike.git/lib/modules/Calendar.pmod/Events.pmod:364:   }      array all_regions()   {    if (!all_data) read_all_data();    return `+(@array_sscanf(all_data,"%{%*s\nRegion \"%s\"%}")[0]);   }      // -----------------------------------------------------------------------    + //! @decl Event.Event `[](string region) + //! @decl Event.Event `->(string region) + //! + //! return the Event object for the specified region or the specified + //! named event. +    program|Event.Event `[](string s)   {    return ::`[](s) || magic_event(s);   }   program|Event.Event `-> (string s) {return `[] (s);}      // Don't load Geogrphy.Countries unless we have to   object country_lookup=0;      Event.Event|Event.Namedays magic_event(string s)