pike.git
/
lib
/
modules
/
Calendar.pmod
/
YMD.pike
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/lib/modules/Calendar.pmod/YMD.pike:11:
// #pragma strict_types inherit Calendar.Time:Time; #include "constants.h" // ---------------- // virtual methods to tell how this calendar works // ----------------
-
static
array(int) year_from_julian_day(int jd);
-
static
int julian_day_from_year(int year);
-
static
int year_remaining_days(int y,int yday);
+
protected
array(int) year_from_julian_day(int jd);
+
protected
int julian_day_from_year(int year);
+
protected
int year_remaining_days(int y,int yday);
-
static
array(int) year_month_from_month(int y,int m); // [y,m,ndays,myd]
-
static
array(int) month_from_yday(int y,int yday); // [m,day-of-month,ndays,myd]
+
protected
array(int) year_month_from_month(int y,int m); // [y,m,ndays,myd]
+
protected
array(int) month_from_yday(int y,int yday); // [m,day-of-month,ndays,myd]
-
static
array(int) week_from_week(int y,int w); // [wy,w,wd,ndays,wjd]
-
static
array(int) week_from_julian_day(int jd); // [wy,w,wd,ndays,wjd]
+
protected
array(int) week_from_week(int y,int w); // [wy,w,wd,ndays,wjd]
+
protected
array(int) week_from_julian_day(int jd); // [wy,w,wd,ndays,wjd]
-
static
string f_month_name_from_number;
-
static
string f_month_shortname_from_number;
-
static
string f_month_number_from_name;
-
static
string f_month_day_name_from_number;
-
static
string f_week_name_from_number;
-
static
string f_week_day_number_from_name;
-
static
string f_week_day_shortname_from_number;
-
static
string f_week_day_name_from_number;
-
static
string f_year_name_from_number;
-
static
string f_year_number_from_name;
+
protected
string f_month_name_from_number;
+
protected
string f_month_shortname_from_number;
+
protected
string f_month_number_from_name;
+
protected
string f_month_day_name_from_number;
+
protected
string f_week_name_from_number;
+
protected
string f_week_day_number_from_name;
+
protected
string f_week_day_shortname_from_number;
+
protected
string f_week_day_name_from_number;
+
protected
string f_year_name_from_number;
+
protected
string f_year_number_from_name;
-
static
int(0..1) year_leap_year(int y);
+
protected
int(0..1) year_leap_year(int y);
-
static
int compat_week_day(int n);
+
protected
int compat_week_day(int n);
//------------------------------------------------------------------------ //! class YMD //! Base (virtual) time period of the Roman-kind of calendar. //! inherits TimeRange //------------------------------------------------------------------------ class YMD { inherit TimeRange;
pike.git/lib/modules/Calendar.pmod/YMD.pike:619:
tzname_utc_offset()); } string format_elapsed() { return sprintf("%dd",number_of_days()); } // --- size and move ---
-
static
TimeRange _set_size(int n,TimeRange t)
+
protected
TimeRange _set_size(int n,TimeRange t)
{ if (t->is_timeofday) return second()->set_size(n,t); if (yd==1 && t->is_year) return Year("ymd_y",rules,y,yjd,t->n*n) ->autopromote(); // months are even on years if (t->is_year || t->is_month)
pike.git/lib/modules/Calendar.pmod/YMD.pike:654:
// fallback on days if (t->is_ymd) return Day("ymd_ydmw",rules,y,yjd,jd,yd, n*t->number_of_days(),m,md,wy,w,wd,mnd); error("set_size: incompatible class %O\n", object_program(t)); }
-
static
TimeRange _add(int _n,TimeRange step)
+
protected
TimeRange _add(int _n,TimeRange step)
{ if (step->is_ymd) return _move(_n,step); if (step->is_timeofday) if (n) return second()->range(second(-1))->add(_n,step); else return second()->beginning()->add(_n,step); error("add: incompatible class %O\n",
pike.git/lib/modules/Calendar.pmod/YMD.pike:906:
array(TimeRange) res=weeks(num,num); if (sizeof(res)==1) return res[0]; error("not in range (Week 1..%d exist)\n", number_of_weeks()); } // --- functions to conform to Time.*
-
static
TimeRange get_unit(string unit,int m)
+
protected
TimeRange get_unit(string unit,int m)
{ if (!n) return day()[unit](); if (m<0) m+=::`[]("number_of_"+unit+"s")(); array(TimeRange) res=::`[](unit+"s")(m,m); if (sizeof(res)==1) return res[0]; error("not in range ("+unit+" 0..%d exist)\n", ::`[]("number_of_"+unit+"s")()-1); }
-
static
array(TimeRange) get_timeofday(string unit,
+
protected
array(TimeRange) get_timeofday(string unit,
int start,int step,program p, int ... range) { int from=0,n=::`[]("number_of_"+unit)(),to=n-1; if (sizeof(range)) if (sizeof(range)<2) error("Illegal numbers of arguments to "+unit+"()\n"); else {
pike.git/lib/modules/Calendar.pmod/YMD.pike:1099:
switch (t) { case 't': return "Calendar."+calendar_name()+".YMD"; default: return ::_sprintf(t,m); } } void create_julian_day(int|float jd);
-
static
TimeRange _move(int n,YMD step);
+
protected
TimeRange _move(int n,YMD step);
TimeRange place(TimeRange what,void|int force); // not needed YMD autopromote() { return this; } } //------------------------------------------------------------------------ //! class Year //! This is the time period of a year.
pike.git/lib/modules/Calendar.pmod/YMD.pike:1273:
// return week()->add(m,step)->set_size(this); if (step->is_ymd) return Day("ymd_jd",rules, yjd+m*step->number_of_days(),number_of_days()) ->autopromote(); error("_move: Incompatible type %O\n",step); }
-
static
void convert_from(TimeRange other)
+
protected
void convert_from(TimeRange other)
{ #if 0 // The following is disabled since it leads to inconsistent // behavior with other time ranges when they are converted to // partly overlapping time ranges. If the user wants to convert // a week to the year it "unambiguously" belongs to, (s)he can // do Calendar.ISO.Year(week->year_no()). if (other->is_week) { // Weeks aren't even on years but they still unambiguously // belong to years. We therefore convert using the week year
pike.git/lib/modules/Calendar.pmod/YMD.pike:1604:
int d2=to->jd; if (d2<d1) error("distance: negative distance (%d days)\n",d2-d1); return Day("ymd_ydmw",rules,y,yjd,jd,yd,d2-d1,m,1,wy,w,wd,mnd) ->autopromote(); } error("distance: Incompatible type %O\n",to); }
-
static
void convert_from(TimeRange other)
+
protected
void convert_from(TimeRange other)
{ ::convert_from(other); if (other->number_of_months) n=other->number_of_months(); else n=0; } TimeRange _move(int x,YMD step) {
pike.git/lib/modules/Calendar.pmod/YMD.pike:1695:
return n; } cMonth set_ruleset(Calendar.Ruleset r) { return Month("ymd_yjmw",r,y,yjd,jd,m,n,wd,w,wy); } // --- needs to be defined
-
static
int months_to_month(int y,int m);
+
protected
int months_to_month(int y,int m);
} // ---------------------------------------------------------------- //! class Week //! The Calendar week represents a standard time period of //! a week. In the Gregorian calendar, the standard week //! starts on a sunday and ends on a saturday; in the ISO //! calendar, it starts on a monday and ends on a sunday. //! //! The week are might not be aligned to the year, and thus
pike.git/lib/modules/Calendar.pmod/YMD.pike:1927:
int d2=to->julian_day(); if (d2<d1) error("distance: negative distance (%d days)\n",d2-d1); return Day("ymd_ydmw",rules,y,yjd,jd,yd,d2-d1,m,md,wy,w,1,mnd) ->autopromote(); } error("distance: Incompatible type %O\n",to); }
-
static
void convert_from(TimeRange other)
+
protected
void convert_from(TimeRange other)
{ ::convert_from(other); if (other->number_of_weeks) n=other->number_of_weeks(); else n=0; } TimeRange _move(int x,YMD step) {
pike.git/lib/modules/Calendar.pmod/YMD.pike:2057:
return ::day(@mp); } cWeek set_ruleset(Calendar.Ruleset r) { return Week("ymd_yjwm",r,y,yjd,jd,wy,w,n,md,m,mnd); } // --- needs to be defined
-
static
int weeks_to_week(int y,int m);
+
protected
int weeks_to_week(int y,int m);
} // ---------------------------------------------------------------- // Day // ---------------------------------------------------------------- class cDay { inherit YMD;
pike.git/lib/modules/Calendar.pmod/YMD.pike:2265:
{ return Day("ymd_ydmw",rules,y,yjd,jd,yd,0,m,md,wy,w,wd,mnd); } TimeRange end() { return Day("ymd_jd",rules,jd+n,0) ->autopromote(); }
-
static
void convert_from(TimeRange other)
+
protected
void convert_from(TimeRange other)
{ ::convert_from(other); if (other->number_of_days) n=other->number_of_days(); else n=0; } // --- Day _move
-
static
TimeRange _move(int x,YMD step)
+
protected
TimeRange _move(int x,YMD step)
{ if (step->is_year) { TimeRange stepped = year()->add(x,step); if (TimeRange placed = stepped->place(this,0)) return placed; // If we couldn't place our day in the target year it means // we're on a leap day and the target year doesn't have any. // We return the closest day in the same month. TimeRange placed = stepped->place (month()); if (md == CALUNKNOWN) make_month();
pike.git/lib/modules/Calendar.pmod/YMD.pike:2640:
//! IST Asia/Jerusalem [UTC+2] //! WST Australia/Perth [UTC+8] //! </pre> //! //! This mapping is modifiable in the ruleset, see //! <ref>Ruleset.set_abbr2zone</ref>. // dwim time of day; needed to correct timezones // this API may change without further notice
-
static
TimeRange dwim_tod(TimeRange origin,string whut,int h,int m,int s)
+
protected
TimeRange dwim_tod(TimeRange origin,string whut,int h,int m,int s)
{ TimeRange tr; if (catch { tr=origin[whut](h,m,s); }) { if (h==24 && m==0 && s==0) // special case return origin->end()->second(); else { object d=origin->day(); array(cHour) ha=origin->hours();
pike.git/lib/modules/Calendar.pmod/YMD.pike:2674:
if (tr->minute_no()!=m) tr=tr->add(m-tr->minute_no(),Minute); if (tr->second_no()!=s) tr=tr->add(s-tr->second_no(),Second); if (tr->hour_no()!=h || tr->minute_no()!=m || tr->second_no()!=s) return 0; // no such hour } return tr; }
-
static
mapping abbr2zones;
+
protected
mapping abbr2zones;
// dwim timezone and call dwim time of day above // this API may change without further notice
-
static
TimeRange dwim_zone(TimeRange origin,string zonename,
+
protected
TimeRange dwim_zone(TimeRange origin,string zonename,
string whut,int ...args) { if (zonename=="") return 0; if (zonename[0]=='"') sscanf(zonename,"\"%s\"",zonename); sscanf(zonename,"%*[ \t]%s",zonename); if(sizeof(zonename)==4 && zonename[2]=='S') zonename = zonename[0..1] + zonename[3..3]; else if(sizeof(zonename)>4 && has_suffix(zonename, "DST"))
pike.git/lib/modules/Calendar.pmod/YMD.pike:2724:
{ TimeRange try=dwim_zone(origin,zn,whut,@args); if (try && try->tzname()==zonename) return try; } return 0; } else return dwim_tod(origin->set_timezone(zone),whut,@args); }
-
static
mapping(string:array) parse_format_cache=([]);
+
protected
mapping(string:array) parse_format_cache=([]);
-
static
mapping dwim_year=([ "past_lower":70, "past_upper":100,
+
protected
mapping dwim_year=([ "past_lower":70, "past_upper":100,
"current_century":2000, "past_century":1900 ]); TimeRange parse(string fmt,string arg,void|TimeRange context) { [string nfmt,array q]=(parse_format_cache[fmt]||({0,0})); if (!nfmt) { // nfmt=replace(fmt," %","%*[ \t]%"); // whitespace -> whitespace #define ALNU "%[^ -,./:-?[-`{-¿-]"
pike.git/lib/modules/Calendar.pmod/YMD.pike:3008:
Calendar.dwim_day("mon w12"); Calendar.dwim_day("monday" ); Calendar.dwim_day("1"); Calendar.dwim_day("today"); Calendar.dwim_day("last monday"); Calendar.dwim_day("next monday"); Calendar.dwim_day("Sat Jun 2"); */
-
static
constant dwim_day_strings=
+
protected
constant dwim_day_strings=
({ "%y-%M-%D (%*s) -W%W-%e (%e)", "%y-%M-%D", "%M/%D/%y", "%D%*[ /]%M%*[- /,]%y", "%M %D%*[- /,]%y", "%e%*[, ]%D%*[a-z:]%*[ /]%M%*[-/ ,]%y", "%e%*[, ]%M%*[ ,]%D%*[ ,]%y", "-%y%*[ /]%D%*[ /]%M", "-%y%*[ /]%M%*[ /]%D",
pike.git/lib/modules/Calendar.pmod/YMD.pike:3217:
string format_day_iso(int|void unix_time) { return Day("unix",unix_time||time())->format_iso(); } string format_day_iso_short(int|void unix_time) { return Day("unix",unix_time||time())->format_iso_short(); }
+