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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/YMD.pmod:368:   //! week_short "2000w22" [2]   //! month "2000-06"   //! month_short "200006" [1]   //! iso_time "2000-06-02 (Jun) -W22-5 (Fri) 00:00:00 UTC+1" [2]   //! ext_time "Friday, 2 June 2000, 00:00:00" [2]   //! ctime "Fri Jun 2 00:00:00 2000\n" [2] [3]   //! http "Fri, 02 Jun 2000 00:00:00 GMT" [4]   //! time "2000-06-02 00:00:00"   //! time_short "20000602 00:00:00"   //! time_xshort "000602 00:00:00" + //! iso_short "2000-06-02T00:00:00"   //! mtime "2000-06-02 00:00"   //! xtime "2000-06-02 00:00:00.000000"   //! tod "00:00:00"   //! tod_short "000000"   //! todz "00:00:00 CET"   //! todz_iso "00:00:00 UTC+1"   //! xtod "00:00:00.000000"   //! mod "00:00"   //! </pre>   //! <tt>[1]</tt> note conflict (think 1 February 2003)
pike.git/lib/modules/Calendar.pmod/YMD.pmod:496:    string format_time()    {    return format_ymd()+" 00:00:00";    }       string format_time_short()    {    return format_ymd_short()+" 00:00:00";    }    +  string format_iso_short() +  { +  return format_ymd_short()+"T00:00:00"; +  } +     string format_time_xshort()    {    return format_ymd_xshort()+" 00:00:00";    }       string format_mtime()    {    return format_ymd_short()+" 00:00";    }   
pike.git/lib/modules/Calendar.pmod/YMD.pmod:990:    return ({Fraction("timeofday_f",rules,unix_time(),0,    (int)to,(int)(inano*(to-(int)to)))    ->autopromote()});    }      // ----------------------------------------   // virtual functions needed   // ----------------------------------------       string nice_print(); -  string _sprintf(int t); +  string _sprintf(int t,mapping m) +  { +  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);    TimeRange place(TimeRange what,void|int force);      // not needed       YMD autopromote() { return this; }   }   
pike.git/lib/modules/Calendar.pmod/YMD.pmod:1107:    return Year("ymd_y",rules,y,yjd,0);    }       TimeRange end()    {    return Year("ymd_yn",rules,y+n,0);    }      // ----------------    -  string _sprintf(int t) +  string _sprintf(int t,mapping m)    {    switch (t)    {    case 'O':    if (n!=1)    return sprintf("Year(%s)",nice_print_period());    return sprintf("Year(%s)",nice_print()); -  +  case 't': +  return "Calendar."+calendar_name()+".Year";    default: -  return 0; +  return ::_sprintf(t,m);    }    }       string nice_print_period()    {    if (!n) return nice_print()+" sharp";    return sprintf("%s..%s",nice_print(),year(-1)->nice_print());    }       string nice_print()
pike.git/lib/modules/Calendar.pmod/YMD.pmod:1185:    return Day("ymd_yd",rules,y,yjd,yjd+yd-1,yd,what->n);    }       if (what->is_week)    {    cWeek week=Week("ymd_yw",rules,y,what->w,what->n);    if (!force && week->y!=y) return 0; // not this year    return week;    }    +  if (what->is_year) +  return Year("ymd_yn",rules,y,what->number_of_years()); +  +  if (what->is_month) +  return month(what->month_name()); +  +  if (what->is_timeofday) +  return place(what->day(),force)->place(what,force); +     error("place: Incompatible type %O\n",what);    }       TimeRange distance(TimeRange to)    {    if (to->is_timeofday)    {    return hour()->distance(to);    }    if (to->is_ymd)
pike.git/lib/modules/Calendar.pmod/YMD.pmod:1380:    [y,yjd]=year_from_julian_day(jd=_jd);    [m,zmd,nd,yd]=month_from_yday(y,1+jd-yjd);    jd=yd+yjd-1;       n=1;    md=1;    nw=wd=w=CALUNKNOWN; // unknown    }    }    -  string _sprintf(int t) +  string _sprintf(int t,mapping m)    {   // return sprintf("month y=%d yjd=%d m=%d jd=%d yd=%d n=%d nd=%d",   // y,yjd,m,jd,yd,n,number_of_days());    switch (t)    {    case 'O':    if (n!=1)    return sprintf("Month(%s)",nice_print_period());    return sprintf("Month(%s)",nice_print()); -  +  case 't': +  return "Calendar."+calendar_name()+".Month";    default: -  return 0; +  return ::_sprintf(t,m);    }    }       string nice_print()    {    return sprintf("%s %s", month_name(), year_name());    }       string format_nice()    {
pike.git/lib/modules/Calendar.pmod/YMD.pmod:1495:    }       TimeRange place(TimeRange what,void|int force)    {    if (what->is_year)    return year()->place(what,force); // just fallback       if (what->is_day)    return place_day(what->month_day(),what->n,force);    +  if (what->is_month) +  return Month("ymd_ym",rules,y,m,what->number_of_months()) +  ->autopromote(); +  +  if (what->is_week) +  return place(what->day(),force)->week(); +  +  if (what->is_timeofday) +  return place(what->day(),force)->place(what,force); +     error("place: Incompatible type %O\n",what);    }      // --- Month to other units       int number_of_years()    {    if (n<=1) return 1;       [int y2,int m2,int nd2,int yd2]=year_month_from_month(y,m+n);
pike.git/lib/modules/Calendar.pmod/YMD.pmod:1664:    yjd=julian_day_from_year(y);    yd=1+jd-yjd;       n=1;    wd=1;    wy=y;    md=m=CALUNKNOWN; // unknown    }    }    -  string _sprintf(int t) +  string _sprintf(int t,mapping m)    {   // return sprintf("week y=%d yjd=%d w=%d jd=%d yd=%d n=%d nd=%d",   // y,yjd,w,jd,yd,n,number_of_days());    switch (t)    {    case 'O':    if (n!=1)    return sprintf("Week(%s)",nice_print_period());    return sprintf("Week(%s)",nice_print()); -  +  case 't': +  return "Calendar."+calendar_name()+".Week";    default: -  return 0; +  return ::_sprintf(t,m);    }    }       string nice_print()    {    return    sprintf("%s %s",    week_name(),    year_name());    }
pike.git/lib/modules/Calendar.pmod/YMD.pmod:1793:    }       TimeRange place(TimeRange what,void|int force)    {    if (what->is_supertimerange)    return what->mend_overlap(map(what->parts,place,force));   // return `|(@map(what->parts,place,force));       if (what->is_year)    return year()->place(what,force); // just fallback +  if (what->is_month) +  return month()->place(what,force); // just fallback    -  +  if (what->is_week) +  return Week("ymd_yw",rules,y,w,what->number_of_weeks()); +     if (what->is_day)    return place_day(what->week_day(),what->n,force);       if (what->is_timeofday)    return place(what->day(),force)->place(what,force);       error("place: Incompatible type %O\n",what);    }      // --- Week to other units
pike.git/lib/modules/Calendar.pmod/YMD.pmod:2013:    {    create_unixtime_default((int)((jd-2440588)*86400));    }    else    {    [y,yjd]=year_from_julian_day(jd=_jd);    yd=1+jd-yjd;    }    }    -  string _sprintf(int t) +  string _sprintf(int t,mapping m)    {    switch (t)    {    case 'O':    if (n!=1)    return sprintf("Day(%s)",nice_print_period());    return sprintf("Day(%s)",nice_print()); -  +  case 't': +  return "Calendar."+calendar_name()+".Day";    default: -  return 0; +  return ::_sprintf(t,m);    }    }       string nice_print()    {    if (m==CALUNKNOWN) make_month();    if (wd==CALUNKNOWN) make_week();    return    sprintf("%s %s %s %s",    week_day_shortname(),
pike.git/lib/modules/Calendar.pmod/YMD.pmod:2098:    if (step->is_week)    return week()->add(x,step)->place(this_object(),1);       if (step->is_day)    return Day("ymd_jd",rules,jd+x*step->n,n)    ->autopromote();       error("_move: Incompatible type %O\n",step);    }    -  TimeRange place(TimeRange what) +  TimeRange place(TimeRange what,int|void force)    {    if (what->is_timeofday)    {    int lux=    what->ux-    Day("unix_r",what->unix_time(),what->ruleset())    ->unix_time(); -  +  TimeRange res;       if (what->is_timeofday_f) -  return +  res=    Fraction("timeofday_f",rules, -  lux+unix_time(),what->ns,what->s_len,what->ns_len) -  ->autopromote(); +  lux+unix_time(),what->ns,what->s_len,what->ns_len); +  else +  res=Second("timeofday",rules,unix_time()+lux,what->len);    -  return Second("timeofday",rules,unix_time()+lux,what->len) -  ->autopromote(); +  if (what->rules->timezone->is_dst_timezone || +  rules->timezone->is_dst_timezone) +  { +  int u0=what->utc_offset()-what->day()->utc_offset(); +  int u1=res->utc_offset()-utc_offset(); + // werror("%O %O\n",u0,u1); +  if (u1-u0) +  res=res->add(u1-u0,Second); +  else +  res=res->autopromote(); +  +  if (!force) +  { +  if (res->hour_no()!=what->hour_no()) +  error("place: no such time of " +  "day (DST shift)\n",what,this_object());    } -  +  } +  else +  res=res->autopromote();    -  +  return res; +  } +  +  if (what->is_year) +  return year()->place(what,force); // just fallback +  if (what->is_month) +  return month()->place(what,force); // just fallback +  if (what->is_week) +  return week()->place(what,force); // just fallback +  +  if (what->is_day) +  return Day("ymd_jd",rules,jd,what->number_of_days()) +  ->autopromote(); +     error("place: Incompatible type %O\n",what);    }       TimeRange distance(TimeRange to)    {    if (to->is_timeofday)    return hour()->distance(to);    if (to->is_ymd)    {    int d1=jd;
pike.git/lib/modules/Calendar.pmod/YMD.pmod:2469:   static mapping(string:array) parse_format_cache=([]);      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 "%[^- -,./:-?[-`{-¿]" - #define AMPM "%[ampAMP]" + #define AMPM "%[ampAMP.]"   #define NUME "%[0-9]"   #define ZONE "%[-+0-9A-Za-z/]"    nfmt=replace(fmt,    ({"%Y","%y","%M","%W","%D","%a","%e","%h","%m","%s","%p",    "%t","%f","%d","%z","%n"}),    ({ALNU,ALNU,ALNU,"%d",NUME,"%d",ALNU,"%d","%d","%d",AMPM,    NUME,NUME,NUME,ZONE,"%s"}));      #if 1    q=array_sscanf(fmt,"%{%*[^%]%%%1s%}")*({})*({})-({"*","%"});
pike.git/lib/modules/Calendar.pmod/YMD.pmod:2635:    }    else    {    if (!zero_type(m->h)) h=m->h,g="hour";    if (!zero_type(m->m)) mi=m->m,g="minute";    if (!zero_type(m->s)) s=m->s,g="second";    }       if (!zero_type(m->p))    { -  switch (lower_case(m->p)) +  switch (lower_case(m->p)-".")    {    case "am":    if (h==12) h=0;    break;    case "pm":    if (h!=12) h+=12;    break;    default:    return 0; // need "am" or "pm"    }
pike.git/lib/modules/Calendar.pmod/YMD.pmod:2723:   Calendar.dwim_day("3/20" );   Calendar.dwim_day("march 20");   Calendar.dwim_day("mon w12 -00" );   Calendar.dwim_day("1 w12 2000");   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=   ({    "%y-%M-%D (%*s) -W%W-%e (%e)",    "%y-%M-%D",    "%M/%D/%y",    "%D%*[ /]%M%*[- /,]%y",    "%M %D%*[- /,]%y",
pike.git/lib/modules/Calendar.pmod/YMD.pmod:2744:    "%e%*[, ]%M%*[ ,]%D%*[ ,]%y",    "-%y%*[ /]%D%*[ /]%M",    "-%y%*[ /]%M%*[ /]%D",    "%y%*[ /]%M%*[ /]%D",    "%y%*[ /]%D%*[ /]%M",    "%D.%M.%y",    "%D%*[- /]%M",    "%M%*[- /]%D",    "%M-%D-%y",    "%D-%M-%y", +  "%e%*[- /]%D%*[- /]%M", +  "%e%*[- /]%M%*[- /]%D",    "%e%*[- /wv]%W%*[ -/]%y",    "%e%*[- /wv]%W",    "%d"   });      cDay dwim_day(string day,void|TimeRange context)   {    cDay d;       foreach ( dwim_day_strings,
pike.git/lib/modules/Calendar.pmod/YMD.pmod:2835:    {   // werror("try: %O\n %O\n",   // dayformat+"%*[ ,]"+todformat,   // todformat+"%*[ ,]"+dayformat);    if (dayformat=="")    {    if ( (t=parse(todformat+"%*[ ]%n",what,cx)) ) return t;    }    else    { -  if ( (t=parse(dayformat+"%*[ ,]"+todformat,what,cx)) ) return t; -  if ( (t=parse(todformat+"%*[ ,]"+dayformat,what,cx)) ) return t; +  if ( (t=parse(dayformat+"%*[ ,:]"+todformat,what,cx)) ) return t; +  if ( (t=parse(todformat+"%*[ ,:]"+dayformat,what,cx)) ) return t;    }    }       error("Failed to dwim time from %O\n",what);   }      //-- auxillary functions------------------------------------------------      //!   //! function datetime(int|void unix_time)