5550a21998-01-27Mirar (Pontus Hagland) // IS-8601, international standard
f250e31998-03-26Mirar (Pontus Hagland) inherit Calendar.Gregorian:Gregorian;
5550a21998-01-27Mirar (Pontus Hagland)  class Year {
f250e31998-03-26Mirar (Pontus Hagland)  inherit Gregorian::Year;
5550a21998-01-27Mirar (Pontus Hagland)  int leap_day() { if (y>1999) return 31+29-1; // 29 Feb return 31+24-1; // 24 Feb }
071d021998-09-27Mirar (Pontus Hagland)  string name() { return (string)y; }
5550a21998-01-27Mirar (Pontus Hagland) }
7d6bbc1999-02-13Fredrik Noring class Month { inherit Gregorian::Month;
c638aa1999-02-15Fredrik Noring  string iso_name()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("%04d-%02d", (int)this->year(), (int)this); }
c638aa1999-02-15Fredrik Noring  string iso_short_name()
7d6bbc1999-02-13Fredrik Noring  { return name()-"-"; } }
5550a21998-01-27Mirar (Pontus Hagland) class Week {
f250e31998-03-26Mirar (Pontus Hagland)  inherit Gregorian::Week;
5550a21998-01-27Mirar (Pontus Hagland)  int yday() { return ({0,-1,-2,-3,3,2,1})[this->year()->julian_day(0)%7] +7*(w-1); } array(mixed) days() { return ({1,2,3,4,5,6,7}); }
7d6bbc1999-02-13Fredrik Noring 
c638aa1999-02-15Fredrik Noring  string iso_name()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("%04d-W%02d", (int)this->year(), (int)this); }
c638aa1999-02-15Fredrik Noring  string iso_short_name()
7d6bbc1999-02-13Fredrik Noring  { return name()-"-"; }
5550a21998-01-27Mirar (Pontus Hagland)  object day(int|string|object n) { if (stringp(n)) { if (!week_day_mapping) week_day_mapping= mkmapping(Array.map(week_day_names,lower_case), ({1,2,3,4,5,6,7})); n=week_day_mapping[n]; } else if (objectp(n)) if (object_program(n)==vDay) n=n->week_day(); else return 0; if (n<0) n=8+n; else if (!n) n=1; n+=this->yday()-1; if (n<0) return vYear(y-1)->day(n); if (n>=this->year()->number_of_days()) return vYear(y+1)->day(n-this->year()->number_of_days()); return vDay(y,n); } } class Day {
f250e31998-03-26Mirar (Pontus Hagland)  inherit Gregorian::Day;
5550a21998-01-27Mirar (Pontus Hagland)  int week_day() { return julian_day()%7+1; } string week_day_name() { return week_day_names[(this->week_day()+6)%7]; }
c638aa1999-02-15Fredrik Noring  string iso_name()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("%04d-%02d-%02d", (int)this->year(), (int)this->month(), (int)this->month_day()); }
c638aa1999-02-15Fredrik Noring  string iso_short_name()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return iso_name()-"-";
7d6bbc1999-02-13Fredrik Noring  }
c638aa1999-02-15Fredrik Noring  string iso_name_by_week()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("%04d-W%02d-%d", (int)this->year(), (int)this->week(), (int)this->week_day()); }
c638aa1999-02-15Fredrik Noring  string iso_name_by_yearday()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("%04d-%03d", (int)this->year(), (int)this->year_day()); }
c638aa1999-02-15Fredrik Noring  string iso_short_name_by_yearday()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return iso_name_by_yearday()-"-";
7d6bbc1999-02-13Fredrik Noring  }
5550a21998-01-27Mirar (Pontus Hagland)  object week() { int n; object ye=this->year(); n=(-({0,-1,-2,-3,3,2,1})[this->year()->julian_day(0)%7]+d)/7+1; if (n>ye->number_of_weeks()) return ye->next()->week(1); else if (n<=0) return ye->prev()->week(-1); return vWeek(y,n); } }
7d6bbc1999-02-13Fredrik Noring  static private class _Day { // FIXME: Kludge because the day object does not exist in // Minute and Second. This function will be shadowed in Hour. object day() { return this_object()->hour()->day(); } } static private class Name { object this = this_object();
c638aa1999-02-15Fredrik Noring  string iso_name()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return this->day()->iso_name()+this->_iso_name();
7d6bbc1999-02-13Fredrik Noring  }
c638aa1999-02-15Fredrik Noring  string iso_short_name()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return this->day()->iso_short_name()+this->_iso_short_name();
7d6bbc1999-02-13Fredrik Noring  }
c638aa1999-02-15Fredrik Noring  string iso_name_by_week()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return this->day()->iso_name_by_week()+this->_iso_name();
7d6bbc1999-02-13Fredrik Noring  }
c638aa1999-02-15Fredrik Noring  string iso_name_by_yearday()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return this->day()->iso_name_by_yearday()+this->_iso_name();
7d6bbc1999-02-13Fredrik Noring  }
c638aa1999-02-15Fredrik Noring  string iso_short_name_by_yearday()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return this->day()->iso_short_name_by_yearday()+this->_iso_short_name();
7d6bbc1999-02-13Fredrik Noring  } } class Hour { inherit Gregorian::Hour; inherit Name;
c638aa1999-02-15Fredrik Noring  string _iso_name()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("T%02d", (int)this); }
c638aa1999-02-15Fredrik Noring  string _iso_short_name()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return _iso_name();
7d6bbc1999-02-13Fredrik Noring  } } class Minute { inherit _Day; inherit Gregorian::Minute; inherit Name;
c638aa1999-02-15Fredrik Noring  string _iso_name()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("T%02d:%02d", (int)this->hour(), (int)this); }
c638aa1999-02-15Fredrik Noring  string _iso_short_name()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return _iso_name()-":";
7d6bbc1999-02-13Fredrik Noring  } } class Second { inherit _Day; inherit Gregorian::Second; inherit Name;
c638aa1999-02-15Fredrik Noring  string _iso_name()
7d6bbc1999-02-13Fredrik Noring  { return sprintf("T%02d:%02d:%02d", (int)this->hour(), (int)this->minute(), (int)this); }
c638aa1999-02-15Fredrik Noring  string _iso_short_name()
7d6bbc1999-02-13Fredrik Noring  {
c638aa1999-02-15Fredrik Noring  return _iso_name()-":";
7d6bbc1999-02-13Fredrik Noring  } }