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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/YMD.pike:1:   //!   //! module Calendar   //! submodule YMD   //!   //! base for all Roman-kind of Calendars,   //! ie, one with years, months, weeks and days   //! + //! inherits Time      #pike __REAL_VERSION__      // #pragma strict_types      inherit Calendar.Time:Time;      #include "constants.h"      // ----------------
pike.git/lib/modules/Calendar.pmod/YMD.pike:37:   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;         protected int(0..1) year_leap_year(int y);      protected int compat_week_day(int n);    + // Polynomial terms for calculating the difference between TDT and UTC. + // + // The polynomials have been taken from NASA: + // @url{http://eclipse.gsfc.nasa.gov/SEhelp/deltatpoly2004.html@} + // + // Each entry is an @expr{array(float)@}: + // @array + // @elem float 0 + // End year for the range. + // @elem float 1 + // Year offset. + // @elem float 2 + // Year divisor. + // @elem float 3.. + // Polynomial factors with the highest exponent last. + // @endarray + protected constant deltat_polynomials = ({ +  ({ -500.0, -1820.0, 100.0, +  -20.0, 0.0, 32.0, }), +  ({ 500.0, 0.0, 100.0, +  10583.6, -1014.41, 33.78311, -5.952053, +  -0.1798452, 0.022174192, 0.0090316521, }), +  ({ 1600.0, -1000.0, 100.0, +  1574.2, -556.01, 71.23472, 0.319781, +  -0.8503463, -0.005050998, 0.0083572073, }), +  ({ 1700.0, -1600.0, 1.0, +  120.0, -0.9808, -0.01532, 0.000140272128, }), +  ({ 1800.0, -1700.0, 1.0, +  8.83, 0.1603, -0.0059285, 0.00013336, -0.000000851788756, }), +  ({ 1860.0, -1800.0, 1.0, +  13.72, -0.332447, 0.0068612, 0.0041116, -0.00037436, +  0.0000121272, -0.0000001699, 0.000000000875, }), +  ({ 1900.0, -1860.0, 1.0, +  7.62, 0.5737, -0.251754, 0.01680668, -0.0004473624, 0.000004288643, }), +  ({ 1920.0, -1900.0, 1.0, +  -2.79, 1.494119, -0.0598939, 0.0061966, -0.000197, }), +  ({ 1941.0, -1920.0, 1.0, +  21.20, 0.84493, -0.076100, 0.0020936, }), +  ({ 1961.0, -1950.0, 1.0, +  29.07, 0.407, -0.0042918455, 0.0003926188, }), +  ({ 1986.0, -1975.0, 1.0, +  45.45, 1.067, -0.0038461538, -0.001392758, }), +  ({ 2005.0, -2000.0, 1.0, +  63.86, 0.3345, -0.060374, 0.0017275, 0.000651814, 0.00002373599, }), +  ({ 2050.0, -2000.0, 1.0, +  62.92, 0.32217, 0.005589, }), +  ({ 2150.0, -1820.0, 100.0, +  -20.0-185.724, 56.28, 32.0, }), +  ({ Math.inf, -1820.0, 100.0, +  -20.0, 0.0, 32.0, }), + }); +  + //! method float deltat(int unadjusted_utc) + //! Terrestrial Dynamical Time difference from standard time. + //! + //! returns + //! An approximation of the difference between TDT and UTC + //! in fractional seconds at the specified time. + //! + //! The zero point is 1901-06-25T14:23:01 UTC + //! (unix time -2162281019), ie the accumulated number + //! of leap seconds since then is returned. + //! + //! note + //! The function is based on polynomials provided by NASA, + //! and the result may differ from actual for dates after 2004. + float deltat(int unadjusted_utc) + { +  // Approximation of the year. This ought to be good enough for +  // most purposes given the uncertainty in the table values. +  // 31556952 == 365.2425 * 24 * 60 * 60. +  float y = 1970.0 + unadjusted_utc/31556952.0; +  +  array(float) polynomial; +  int l, c, h = sizeof(deltat_polynomials); +  do { +  c = (l + h)/2; +  polynomial = deltat_polynomials[c]; +  if (y < polynomial[0]) h = c; +  else l = c + 1; +  } while (l < h); +  polynomial = deltat_polynomials[l]; +  +  float u = (y + polynomial[1])/polynomial[2]; +  +  float deltat = 0.0; +  float p = 1.0; +  foreach(polynomial; int i; float factor) { +  if (i < 3) continue; +  deltat += factor * p; +  p = p * u; +  } +  return deltat; + } +    //------------------------------------------------------------------------   //! 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:144:   //! method string week_name()   //! method string year_name()   //! method string tzname()   //! method string tzname_iso()       int julian_day()    {    return jd;    }    - //! function method int unix_time() + //! method int unix_time()   //! Returns the unix time integer corresponding to the start   //! of the time range object. (An unix time integer is UTC.)       int unix_time()    {   // 1970-01-01 is julian day 2440588    int ux=(jd-2440588)*86400;    if (utco==CALUNKNOWN)    [utco,tzn]=rules->timezone->tz_jd(jd);    return ux+utco;
pike.git/lib/modules/Calendar.pmod/YMD.pike:269:    return rules->language[f_week_day_shortname_from_number](wd);    }       int leap_year() { return year_leap_year(year_no()); }       int hour_no() { return 0; }    int minute_no() { return 0; }    int second_no() { return 0; }    float fraction_no() { return 0.0; }    - //! function method datetime() + //! method mapping datetime()   //! This gives back a mapping with the relevant   //! time information (representing the start of the period);   //! <pre>   //! ([ "year": int // year number (2000 AD=2000, 1 BC==0)   //! "month": int(1..) // month of year   //! "day": int(1..) // day of month   //! "yearday": int(0..) // day of year   //! "week": int(1..) // week of year   //! "week_day": int(0..) // day of week   //! "timezone": int // offset to utc, including dst
pike.git/lib/modules/Calendar.pmod/YMD.pike:406:   //! 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)   //! <br><tt>[2]</tt> language dependent   //! <br><tt>[3]</tt> as from the libc function ctime()   //! <br><tt>[4]</tt> as specified by the HTTP standard;   //! not language dependent. + //! + //! The iso variants aim to be compliant with ISO-8601.       string format_iso_ymd()    {    if (m==CALUNKNOWN) make_month();    if (w==CALUNKNOWN) make_week();    return sprintf("%04d-%02d-%02d (%s) -W%02d-%d (%s)",    y,m,md,    month_shortname(),    w,wd, // fixme - what weekday?    week_day_shortname());
pike.git/lib/modules/Calendar.pmod/YMD.pike:711:    {    int m=number_of_days();    if (m<=1 || m+yd-1<year()->number_of_days()) return 1;    return 1+y-year_from_julian_day(jd+m-1)[0];    }       array(cYear) years(void|int from, void|int to)    {    int n=number_of_years();    -  if (zero_type (from)) { +  if (undefinedp (from)) {    from = 1;    to = n;    }    else -  if (zero_type (to)) +  if (undefinedp (to))    error("Illegal numbers of arguments to years()\n");    else    {    if (from>n) return ({}); else if (from<1) from=1;    if (to>n) to=n; else if (to<from) return ({});    }       return map(enumerate(1+to-from,1,y+from-1),    lambda(int x)    { return Year("ymd_yn",rules,x,1); });    }       cYear year(void|int m)    { -  if (zero_type (m)) m=1; +  if (undefinedp (m)) m=1;       if (!n&&m==-1)    return Year("ymd_y",rules,y,yjd,1);       if (m<0) m += 1 + number_of_years();       array(TimeRange) res=years(m,m);    if (sizeof(res)==1) return res[0];    error("Not in range (Year 1..%d exist)\n",    number_of_years());    }         // days    -  + //! method int number_of_days() + //! Get the number of days in the current range. +     int number_of_days();    -  + //! method array(Day) days(int|void from, int|void to) + //! Get the days in the current range. +     array(cDay) days(void|int from, void|int to)    {    int n=number_of_days();    -  if (zero_type (from)) { +  if (undefinedp (from)) {    from = 1;    to = n;    }    else -  if (zero_type (to)) +  if (undefinedp (to))    error("Illegal number of arguments to days()\n");    else    {    if (from>n) return ({}); else if (from<1) from=1;    if (to>n) to=n; else if (to<from) return ({});    }       int zy=y;    int zyd=yd+from-1;    int zjd=jd+from-1;
pike.git/lib/modules/Calendar.pmod/YMD.pike:795:    zjd+=rd;    to-=rd;    }       [zy,zyjd]=year_from_julian_day(zjd);    zyd=zjd-zyjd+1;    }    return res;    }    + //! method Day day() + //! method Day day(int n) + //! Get day number n in the current range. + //! + //! If n is negative, it is counted from the end of the range. +     cDay day(void|int m, mixed... ignored)    { -  if (zero_type (m)) m=1; +  if (undefinedp (m)) m=1;       if (!n)    return Day("ymd_yd",rules,y,yjd,jd,yd,1);       if (m<0) m+=1+number_of_days();       array(TimeRange) res=days(m,m);    if (sizeof(res)==1) return res[0];    if(number_of_days())    error("Not in range (Day 1..%d exist).\n",
pike.git/lib/modules/Calendar.pmod/YMD.pike:1087:    }    result += ({ start->distance(end) });    return result;    }      // ----------------------------------------   // virtual functions needed   // ----------------------------------------       string nice_print(); -  string _sprintf(int t,mapping m) +  protected string _sprintf(int t,mapping m)    {    switch (t)    {    case 't':    return "Calendar."+calendar_name()+".YMD";    default:    return ::_sprintf(t,m);    }    }   
pike.git/lib/modules/Calendar.pmod/YMD.pike:1135:   //! method void create("julian",int|float julian_day)   //! method void create(int year)   //! method void create(string year)   //! method void create(TimeRange range)   //! It's possible to create the standard year   //! by using three different methods; either the normal   //! way - from standard unix time or the julian day,   //! and also, for more practical use, from the year number.   //!    -  void create(mixed ...args) +  protected void create(mixed ...args)    {    if (!sizeof(args))    {    create_now();    return;    }    else switch (args[0])    {    case "ymd_y":    rules=args[1];
pike.git/lib/modules/Calendar.pmod/YMD.pike:1217:    return Year("ymd_y",rules,y,yjd,0);    }       TimeRange end()    {    return Year("ymd_yn",rules,y+n,0);    }      // ----------------    -  string _sprintf(int t,mapping m) +  protected 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:
pike.git/lib/modules/Calendar.pmod/YMD.pike:1432:    }       cYear set_ruleset(Calendar.Ruleset r)    {    return Year("ymd_y",r,y,yjd,n);    }   }         // ---------------------------------------------------------------- - // Month + //! class Month + //! inherits YMD   // ----------------------------------------------------------------      function(mixed...:cMonth) Month=cMonth;   class cMonth   {    inherit YMD;       constant is_month=1;       int nd; // number of days    int nw; // number of weeks    -  void create(mixed ...args) +  protected void create(mixed ...args)    {    if (!sizeof(args))    {    rules=default_rules;    create_unixtime_default(time());    return;    }    else    switch (args[0])    {
pike.git/lib/modules/Calendar.pmod/YMD.pike:1523:    [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=wy=CALUNKNOWN; // unknown    }    }    -  string _sprintf(int t,mapping m) +  protected 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':
pike.git/lib/modules/Calendar.pmod/YMD.pike:1723:   //! calendar, which modifies this rule for the Gregorian calendar;   //! the week number and year is the same as for the ISO calendar,   //! except for the sundays.   //!   //! When adding, moving and subtracting months   //! to a week, it falls back to using days.   //!   //! When adding, moving or subtracting years,   //! if tries to place the moved week in the   //! resulting year. + //! + //! inherits YMD   // ----------------------------------------------------------------      function(mixed...:cWeek) Week=cWeek;   class cWeek   {    inherit YMD;       // Note: wy, w and wd are never CALUNKNOWN in this class.       constant is_week=1;
pike.git/lib/modules/Calendar.pmod/YMD.pike:1745:   //! method void create("unix",int unix_time)   //! method void create("julian",int|float julian_day)   //! method void create(int year,int week)   //! It's possible to create the standard week   //! by using three different methods; either the normal   //! way - from standard unix time or the julian day,   //! and also, for more practical use, from year and week   //! number.   //!    -  void create(mixed ...args) +  protected void create(mixed ...args)    {    if (!sizeof(args))    {    rules=default_rules;    create_unixtime_default(time());    return;    }    else    switch (args[0])    {
pike.git/lib/modules/Calendar.pmod/YMD.pike:1828:    [wy,w,zwd,int nd,jd]=week_from_julian_day(_jd);    [y,yjd]=year_from_julian_day(_jd);    yd=1+jd-yjd;       n=1;    wd=1;    md=m=CALUNKNOWN; // unknown    }    }    -  string _sprintf(int t,mapping m) +  protected 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':
pike.git/lib/modules/Calendar.pmod/YMD.pike:2061:    {    return Week("ymd_yjwm",r,y,yjd,jd,wy,w,n,md,m,mnd);    }      // --- needs to be defined       protected int weeks_to_week(int y,int m);   }      // ---------------------------------------------------------------- - // Day + //! class Day + //! inherits YMD   // ----------------------------------------------------------------      class cDay   {    inherit YMD;       constant is_day=1;    int nw;      //!
pike.git/lib/modules/Calendar.pmod/YMD.pike:2084:   //! method void create(int year,int month,int day)   //! method void create(int year,int year_day)   //! method void create(int julian_day)   //! It's possible to create the day   //! by using five different methods; either the normal   //! way - from standard unix time or the julian day,   //! and also, for more practical use, from year, month and day,   //! from year and day of year, and from julian day   //! without extra fuzz.    -  void create(mixed ...args) +  protected void create(mixed ...args)    {    if (!sizeof(args))    {    rules=default_rules;    create_unixtime_default(time());    return;    }    else    switch (args[0])    {
pike.git/lib/modules/Calendar.pmod/YMD.pike:2204:    {    create_unixtime_default((int)((jd-2440588)*86400));    }    else    {    [y,yjd]=year_from_julian_day(jd=_jd);    yd=1+jd-yjd;    }    }    -  string _sprintf(int t,mapping m) +  protected string _sprintf(int t,mapping m)    {    switch (t)    {    case 'O':    catch {    if (n!=1)    return sprintf("Day(%s)",nice_print_period());    return sprintf("Day(%s)",nice_print());    };    return sprintf("Day(%d)", unix_time());
pike.git/lib/modules/Calendar.pmod/YMD.pike:2511:   //! inherits YMD   //------------------------------------------------------------------------      class cHour   {    inherit Time::cHour;    inherit YMD_Time;    OVERLOAD_TIMEOFDAY;   }    + //------------------------------------------------------------------------ + //! class Minute + //! inherits Time.Minute + //! inherits YMD + //------------------------------------------------------------------------ +    class cMinute   {    inherit Time::cMinute;    inherit YMD_Time;    OVERLOAD_TIMEOFDAY;   }    -  + //------------------------------------------------------------------------ + //! class Second + //! inherits Time.Second + //! inherits YMD + //------------------------------------------------------------------------ +    class cSecond   {    inherit Time::cSecond;    inherit YMD_Time;    OVERLOAD_TIMEOFDAY;   }    -  + //------------------------------------------------------------------------ + //! class Fraction + //! inherits Time.Fraction + //! inherits YMD + //------------------------------------------------------------------------ +    class cFraction   {    inherit Time::cFraction;    inherit YMD_Time;    OVERLOAD_TIMEOFDAY;   }    -  + //------------------------------------------------------------------------ + //! class SuperTimeRange + //! inherits Time.SuperTimeRange + //------------------------------------------------------------------------ +    class cSuperTimeRange   {    inherit Time::cSuperTimeRange;       array(cYear) years(int ...range) { return get_units("years",@range); }    cYear year(void|int n) { return get_unit("years",n); }    int number_of_years() { return num_units("years"); }       array(cMonth) months(int ...range) { return get_units("months",@range); }    cMonth month(void|int n) { return get_unit("months",n); }
pike.git/lib/modules/Calendar.pmod/YMD.pike:2584:    string format_iso_week_short() { return RBASE->format_iso_week_short(); }    string format_week() { return RBASE->format_week(); }    string format_week_short() { return RBASE->format_week_short(); }    string format_month() { return RBASE->format_month(); }    string format_month_short() { return RBASE->format_month_short(); }      #undef RBASE   }      //------------------------------------------------------------------------ - //! global convinience functions + // Pop out doc-extractor context to the top-level scope. + //! module Calendar + //! submodule YMD + // global convenience functions   //------------------------------------------------------------------------      //! method TimeRange parse(string fmt,string arg)   //! parse a date, create relevant object   //! fmt is in the format "abc%xdef..."   //! where abc and def is matched, and %x is   //! one of those time units:   //! <pre>   //! %Y absolute year   //! %y dwim year (70-99 is 1970-1999, 0-69 is 2000-2069)
pike.git/lib/modules/Calendar.pmod/YMD.pike:2694:    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"))    zonename = zonename[..<3];       if (origin->rules->abbr2zone[zonename])    zonename=origin->rules->abbr2zone[zonename];    -  Calendar.Rule.Timezone zone=Calendar.Timezone[zonename]; +  Calendar.Rule.Timezone zone = Calendar.Timezone[zonename]; +     if (!zone)    {    if (sscanf(zonename,"%[^+-]%s",string a,string b)==2 && a!="" && b!="")    {    TimeRange tr=dwim_zone(origin,a,whut,@args);    if (!tr) return 0;       return    dwim_tod(origin->set_timezone(    Calendar.Timezone.make_new_timezone(
pike.git/lib/modules/Calendar.pmod/YMD.pike:2720:    abbr2zones = master()->resolv("Calendar")["TZnames"]["abbr2zones"];    array pz=abbr2zones[zonename];    if (!pz) return 0;    foreach (pz,string zn)    {    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);   }      protected mapping(string:array) parse_format_cache=([]);      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)   {
pike.git/lib/modules/Calendar.pmod/YMD.pike:2795: Inside #if undefined(NOCATCH)
  #ifndef NOCATCH    if (catch {   #else    werror("%O\n",m);   #endif    if (m->n && m->n!="") return 0;       if (m->Y)    m->Y=default_rules->language[f_year_number_from_name](m->Y);    -  if (!zero_type(m->Y) && m->D && (int)m->M) +  if (!undefinedp(m->Y) && m->D && (int)m->M)    low=m->day=cal->Day(m->Y,(int)m->M,(int)m->D);          if (m->d)    {    int y,mo,d;       if (sizeof(m->d)==6)    {    [y,mo,d]=(array(int))(m->d/2);
pike.git/lib/modules/Calendar.pmod/YMD.pike:2819:    y+=dwim_year->past_century;    }    else if (sizeof(m->d)==8)    [y,mo,d]=(array(int))array_sscanf(m->d,"%4s%2s%2s");    else return 0;       low=m->day=cal->Day(y,mo,d);    }    else    { -  if (!zero_type(m->Y)) m->year=cal->Year(m->Y); +  if (!undefinedp(m->Y)) m->year=cal->Year(m->Y);    else if (m->y)    {    if (sizeof(m->y)<3)    {    m->y=(int)m->y;    // FIXME? these should be adjustable for different calendars.    if (m->y<dwim_year->past_lower)    m->y+=dwim_year->current_century;    else if (m->y<dwim_year->past_upper)    m->y+=dwim_year->past_century;
pike.git/lib/modules/Calendar.pmod/YMD.pike:2842:    }    else low=m->year=context?context->year():cal->Year();       if (m->M)    {    m->month=low=m->year->month(m->M);    }    if (m->W)    m->week=low=m->year->week("w"+m->W);    -  if (!zero_type(m->D)) +  if (!undefinedp(m->D))    m->day=low=(m->month||(context?context->month():cal->Month()))    ->day((int)m->D); -  else if (!zero_type(m->a)) -  m->day=low=m->year->day(m->a); -  else if (!zero_type(m->e)) +  else if (!undefinedp(m->a)) +  m->day=low=(m->month || m->year)->day(m->a); +  else if (!undefinedp(m->e))    m->day=low=(m->week||(context?context->week():cal->Week()))    ->day(m->e);    else    low=m->day=context?context->day():cal->Day();    -  if (m->day && zero_type(m->Y) && zero_type(m->y) && m->e) +  if (m->day && undefinedp(m->Y) && undefinedp(m->y) && m->e)    if (m->month)    {    // scan for closest year that matches    cYear y2=m->day->year();    object d2;    int i;    for (i=0; i<20; i++)    {    d2=(y2+i)->place(m->day);    if (d2 && d2->week()->day(m->e)==d2) break;
pike.git/lib/modules/Calendar.pmod/YMD.pike:2902:    if (m->t)    {    if (sizeof(m->t)==6)    [h,mi,s]=(array(int))(m->t/2),g="second";    else if (sizeof(m->t)==4)    [h,mi]=(array(int))(m->t/2),g="minute";    else return 0;    }    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->f)) sub_second=(float)("0."+m->f+"0"*9)[..10]; +  if (!undefinedp(m->h)) h=m->h,g="hour"; +  if (!undefinedp(m->m)) mi=m->m,g="minute"; +  if (!undefinedp(m->s)) s=m->s,g="second"; +  if (!undefinedp(m->f)) sub_second=(float)("0."+m->f+"0"*9)[..10];    }    -  if (!zero_type(m->p)) +  if (!undefinedp(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"    }    } -  +     if (m->z) // zone    low = dwim_zone(low,m->z,g,h,mi,s);    else if (g)    low = dwim_tod(low,g,h,mi,s); -  else if (!zero_type(m->S)) +  else if (!undefinedp(m->S))    low = Second(m->S);    if (sub_second)    low = low->fraction(sub_second);    return low;      #ifndef NOCATCH    })   #endif    return 0;   }    - //! function Day dwim_day(string date) - //! function Day dwim_day(string date,TimeRange context) + //! method Day dwim_day(string date) + //! method Day dwim_day(string date,TimeRange context)   //! Tries a number of different formats on the given date (in order):   //! <pre>   //! <ref>parse</ref> format as in   //! "%y-%M-%D (%M) -W%W-%e (%e)" "2000-03-20 (Mar) -W12-1 (Mon)"   //! "%y-%M-%D" "2000-03-20", "00-03-20"   //! "%M%/%D/%y" "3/20/2000"   //! "%D%*[ /]%M%*[ /-,]%y" "20/3/2000" "20 mar 2000" "20/3 -00"   //! "%e%*[ ]%D%*[ /]%M%*[ /-,]%y" "Mon 20 Mar 2000" "Mon 20/3 2000"   //! "-%y%*[ /]%D%*[ /]%M" "-00 20/3" "-00 20 mar"   //! "-%y%*[ /]%M%*[ /]%D" "-00 3/20" "-00 march 20"
pike.git/lib/modules/Calendar.pmod/YMD.pike:3072:    }    if (sscanf(day,"next %s",day))    {    cDay d=dwim_day(day);    return (d->week()+1)->place(d);    }       error("Failed to dwim day from %O\n",day);   }    + //! method Day dwim_time(string date_time) + //! method Day dwim_time(string date_time, TimeRange context) + //! Tries a number of different formats on the given date_time. + //! + //! note: + //! Casts exception if it fails to dwim out a time. + //! "dwim" means do-what-i-mean. +    TimeofDay dwim_time(string what,void|TimeRange cx)   {    TimeofDay t;      // #define COLON "$*[ :]"   #define COLON ":"   #define SPACED(X) replace(X," ","%*[ ]")       what = String.trim_all_whites(what);   
pike.git/lib/modules/Calendar.pmod/YMD.pike:3096:    if (sizeof(what)>15 &&    (t=parse(SPACED("%e %M %D %h:%m:%s %z %Y"),what,cx))) return t;    if (sizeof(what)>19 &&    (t=parse(SPACED("%e %M %D %h:%m:%s %z DST %Y"),what,cx))) return t;       foreach ( dwim_day_strings +    ({""}),    string dayformat )    foreach ( ({ "%t %z",    "T%t %z", +  "T%t%z",    "T%t",    "%h"COLON"%m"COLON"%s %p %z",    "%h"COLON"%m"COLON"%s %p",    "%h"COLON"%m"COLON"%s %z",    "%h"COLON"%m"COLON"%s%z",    "%h"COLON"%m"COLON"%s",    "%h"COLON"%m %p %z",    "%h"COLON"%m %p",    "%h"COLON"%m %z",    "%h"COLON"%m%z",    "%h"COLON"%m", -  +  "T%h"COLON"%m"COLON"%s %z", +  "T%h"COLON"%m"COLON"%s%z", +  "T%h"COLON"%m"COLON"%s", +  "T%h"COLON"%m %z", +  "T%h"COLON"%m%z", +  "T%h"COLON"%m",    "%h%*[ ]%p",    "%*[a-zA-Z.] %h"COLON"%m"COLON"%s %p %z",    "%*[a-zA-Z.] %h"COLON"%m"COLON"%s %p",    "%*[a-zA-Z.] %h"COLON"%m"COLON"%s %z",    "%*[a-zA-Z.] %h"COLON"%m"COLON"%s%z",    "%*[a-zA-Z.] %h"COLON"%m"COLON"%s",    "%*[a-zA-Z.] %h"COLON"%m %p %z",    "%*[a-zA-Z.] %h"COLON"%m %p",    "%*[a-zA-Z.] %h"COLON"%m %z",    "%*[a-zA-Z.] %h"COLON"%m%z",    "%*[a-zA-Z.] %h"COLON"%m", -  "%*[a-zA-Z.] %h%*[ ]%p", }), +  "%*[a-zA-Z.] %h%*[ ]%p", +  "%t%z", +  "%t", +  }),    string todformat )    {   // 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+"%*[ ,:T]"+todformat,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);   }      // Parses time according to HTTP 1.1 (RFC 2616) HTTP-date token.   TimeofDay http_time(string what, void|TimeRange cx)   {    TimeofDay t;    -  string date1 = "%D %M %Y"; // 2+1+3+1+4=11 -  string date2 = "%D-%M-%y"; // 2+1+3+1+2=9 -  string date3 = "%M %*[ ]%D"; // 2+1+2=5 -  string time = "%h:%m:%s"; // 2+1+2+1+2=8 +  constant date1 = "%D %M %Y"; // 2+1+3+1+4=11 +  constant date2 = "%D-%M-%y"; // 2+1+3+1+2=9 +  constant date3 = "%M %*[ ]%D"; // 2+1+2=5 +  constant time = "%h:%m:%s"; // 2+1+2+1+2=8       // 3+2+ 11 +1+ 8 +4 = 29 -  string rfc1123_date = "%e, "+date1+" "+time+" %z"; +  // RFC 1123 (and RFC 822 which it bases its timestamp format on) +  // supports more variations than we support here. +  constant rfc1123_date = "%e, "+date1+" "+time+" %z";       // 6+2+ 9 +1+ 8 +4 = 33 -  string rfc850_date = "%e, "+date2+" "+time+" %z"; +  constant rfc850_date = "%e, "+date2+" "+time+" %z";       // 3+1+ 5 +1+ 8 +1+4 = 23 -  string asctime_date = "%e "+date3+" "+time+" %Y"; +  constant asctime_date = "%e "+date3+" "+time+" %Y";       if( sizeof(what)<23 ) return 0;       if( (t=parse(rfc1123_date, what, cx)) ||    (t=parse(rfc850_date, what, cx)) ||    (t=parse(asctime_date+" %z", what+" GMT", cx)) )    return t;       return 0;   }      //-- auxillary functions------------------------------------------------      //! - //! function datetime(int|void unix_time) + //! function mapping(string:int) datetime(int|void unix_time)   //! Replacement for localtime; gives back a mapping:   //! <pre>   //! ([ "year": int // year number (2000 AD=2000, 1 BC==0)   //! "month": int(1..) // month of year   //! "day": int(1..) // day of month   //! "yearday": int(1..) // day of year   //! "week": int(1..) // week of year   //! "week_day": int(1..) // day of week (depending on calendar)   //! "unix": int // unix time   //! "julian": float // julian day   //! "hour": int(0..) // hour of day, including dst   //! "minute": int(0..59) // minute of hour   //! "second": int(0..59) // second of minute   //! "fraction": float // fraction of second   //! "timezone": int // offset to utc, including dst   //! ]);   //! </pre>   //! This is the same as calling <ref>Second</ref>()-><ref to=Second.datetime>datetime</ref>().   //! - //! function datetime_name(int|void unix_time) - //! function datetime_short_name(int|void unix_time) + //! function string datetime_name(int|void unix_time) + //! function string datetime_short_name(int|void unix_time)   //! Compat functions; same as <ref>format_iso</ref>   //! and <ref>format_iso_short</ref>.   //!   //! function string format_iso(void|int unix_time)   //! function string format_iso_short(void|int unix_time)   //! function string format_iso_tod(void|int unix_time)   //! function string format_day_iso(void|int unix_time)   //! function string format_day_iso_short(void|int unix_time)   //! Format the object into nice strings;   //! <pre>