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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Events.pmod:6:   mapping loaded_events=([]);   mapping loaded_regions=([]);      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")); +  combine_path(__DIR__,"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:137:    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)) { +  switch(String.trim(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)) { +  switch(String.trim(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",
pike.git/lib/modules/Calendar.pmod/Events.pmod:191:   {    return Event.Namedays(id,name,names,0,    start,stop,leapdayshift);   }      mapping made_namedays=([]);      string read_all_namedays()   {    return master()->master_read_file( -  combine_path(__FILE__,"../events/namedays")); +  combine_path(__DIR__,"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:386:   }      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)