diff --git a/lib/modules/Calendar.pmod/Time.pmod b/lib/modules/Calendar.pmod/Time.pmod index ca8ff676117d237bc9df644bd1db948dd223fd6b..b921bb426197429a460a42e066ae14cc210e1153 100644 --- a/lib/modules/Calendar.pmod/Time.pmod +++ b/lib/modules/Calendar.pmod/Time.pmod @@ -704,6 +704,8 @@ class TimeofDay //! method string format_tod(); //! method string format_xtod(); //! method string format_mod(); +//! method string format_nice(); +//! method string format_nicez(); //! Format the object into nice strings; //! <pre> //! iso_ymd "2000-06-02 (Jun) -W22-5 (Fri)" [2] @@ -720,7 +722,7 @@ class TimeofDay //! iso_time "2000-06-02 (Jun) -W22-5 (Fri) 20:53:14 UTC+1" [2] //! ext_time "Friday, 2 June 2000, 20:53:14" [2] //! ctime "Fri Jun 4 20:53:14 2000\n" [2] [3] -//! http "Fri, 02 Jun 2000 20:53:14 GMT" [4] +//! http "Fri, 02 Jun 2000 19:53:14 GMT" [4] //! time "2000-06-02 20:53:14" //! time_short "20000602 20:53:14" //! time_xshort "000602 20:53:14" @@ -732,14 +734,20 @@ class TimeofDay //! tod_short "205314" //! xtod "20:53:14.000000" //! mod "20:53" +//! nice "2 Jun 20:53", "2 Jun 2000 20:53:14" [2][5] +//! nicez "2 Jun 20:53 CET" [2][5] +//! smtp "Fri, 2 Jun 2000 20:53:14 +0100" [6] //! </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; -//! this is always in GMT, ie, UTC. The timezone calculations -//! needed will be executed implicitly. It is not language -//! dependent. +//! this is always in GMT, ie, UTC. The timezone calculations +//! needed will be executed implicitly. It is not language +//! dependent. +//! <br><tt>[5]</tt> adaptive to type and with special cases +//! for yesterday, tomorrow and other years +//! <br><tt>[6]</tt> as seen in Date: headers in mails string format_ext_ymd(); string format_iso_ymd(); @@ -753,6 +761,8 @@ class TimeofDay string format_month(); string format_month_short(); + string format_nice(); + string format_iso_time() { return this_object()->format_iso_ymd()+" "+format_todz_iso(); @@ -853,6 +863,25 @@ class TimeofDay 0); } + string format_nice(); + string format_nicez() + { + return format_nice()+" "+tzname(); + } + + string format_smtp() + { + if (ls==CALUNKNOWN) make_local(); + int u=utc_offset(); + return sprintf("%s, %s %s %s %d:%02d:%02d %+03d%02d", + base->week_day_name(), + base->month_day_name(), + base->month_shortname(), + base->year_name(), + ls/3600, (ls/60)%60, ls%60, + -u/3600,max(u,-u)/60%60); + } + string format_elapsed() { string res=""; @@ -869,7 +898,6 @@ class TimeofDay left->len%60); } - // -------- TimeofDay set_ruleset(Ruleset r) @@ -1197,6 +1225,13 @@ class cHour if (ls==CALUNKNOWN) make_local(); return sprintf("%d:00 %s",ls/3600,tzname()); } + + string format_nice() + { + if (ls==CALUNKNOWN) make_local(); + if (!base) make_base(); + return base->format_nice()+" "+sprintf("%d:00",ls/3600); + } } //------------------------------------------------------------------------ @@ -1265,6 +1300,13 @@ class cMinute if (ls==CALUNKNOWN) make_local(); return sprintf("%d:%02d %s",ls/3600,(ls/60)%60,tzname()); } + + string format_nice() + { + if (ls==CALUNKNOWN) make_local(); + if (!base) make_base(); + return base->format_nice()+" "+sprintf("%d:%02d",ls/3600,(ls/60)%60); + } } //------------------------------------------------------------------------ @@ -1333,6 +1375,14 @@ class cSecond return sprintf("%d:%02d:%02d %s",ls/3600,ls/60%60,ls%60,tzname()); } + string format_nice() + { + if (ls==CALUNKNOWN) make_local(); + if (!base) make_base(); + return base->format_nice()+" "+ + sprintf("%d:%02d:%02d",ls/3600,ls/60%60,ls%60); + } + // backwards compatible with calendar I string iso_name() { return this_object()->format_ymd()+" T"+format_tod(); } @@ -1553,6 +1603,15 @@ class cFraction ls/3600,ls/60%60,ls%60,ns/1000,tzname()); } + string format_nice() + { + if (ls==CALUNKNOWN) make_local(); + if (!base) make_base(); + return base->format_nice()+" "+ + sprintf("%d:%02d:%02d.%06d", + ls/3600,ls/60%60,ls%60,ns/1000); + } + TimeofDay autopromote() { if (!ns && !len_ns) diff --git a/lib/modules/Calendar.pmod/YMD.pmod b/lib/modules/Calendar.pmod/YMD.pmod index 0bf7fc60f052c01a8f6628fb0b8122436f477f8c..ff90b2a8a9724aa92f28fcc1dd5d98cf3a47d2ca 100644 --- a/lib/modules/Calendar.pmod/YMD.pmod +++ b/lib/modules/Calendar.pmod/YMD.pmod @@ -546,6 +546,22 @@ class YMD return "00:00:00.000000"; } + string format_nice(); + string format_nicez() + { + return format_nice()+" "+tzname(); + } + + string format_smtp() + { + if (m==CALUNKNOWN) make_month(); + int u=utc_offset(); + return sprintf("%s, %s %s %s 00:00:00 %+03d%02d", + week_day_name(), + month_day_name(),month_shortname(),year_name(), + -u/3600,max(u,-u)/60%60); + } + string format_elapsed() { return sprintf("%dd",number_of_days()); @@ -1125,6 +1141,11 @@ class cYear return year_name(); } + string format_nice() + { + return year_name(); + } + // --- Year _move TimeRange _move(int m,YMD step) @@ -1386,12 +1407,15 @@ class cMonth string nice_print() { - return - sprintf("%s %s", - month_name(), - year_name()); + return sprintf("%s %s", month_name(), year_name()); + } + + string format_nice() + { + return sprintf("%s %s", month_name(), year_name()); } + string nice_print_period() { if (!n) return day()->nice_print()+" 0:00 sharp"; @@ -1673,6 +1697,14 @@ class cWeek year_name()); } + string format_nice() + { + return + sprintf("%s %s", + week_name(), + year_name()); + } + string nice_print_period() { @@ -2015,6 +2047,20 @@ class cDay year_name()); } + string format_nice() + { + if (m==CALUNKNOWN) make_month(); + if (calendar()->Year()!=year()) + return + sprintf("%s %s %s", + month_day_name(),month_shortname(), + year_name()); + else + return + sprintf("%s %s", + month_day_name(),month_shortname()); + } + string nice_print_period() { // return nice_print()+" n="+n+"";