I was thinking it'd be nice to be able to (en|de)code Calendar objects, but sadly, that doesn't appear to be possible:
int main() { object x = Calendar.Second(); string y = encode_value(x); werror("%O\n", x); sleep(3); werror("%O\n", decode_value(y)); return 0; }
Cannot find Second(Thu 4 Oct 2007 8:40:34 EDT) in ISO. /usr/local/pike/7.7.34/lib/master.pike:4118: master()->find_index (ISO,Second(Thu 4 Oct 2007 8:40:34 EDT),UNDEFINED) /usr/local/pike/7.7.34/lib/master.pike:4311: master()->nameof (@0=Second(Thu 4 Oct 2007 8:40:34 EDT),UNDEFINED) test.pike:4: /main()->main()
Now, I'm pretty sure that Calendar.ISO.Second exists, but I know there's a lot of black magic in the Calendar module, so I'm not even sure where to begin. Anyone have any suggestions?
Bill
I think it is a bit too much magic in there for me, and I also would want the _encode/_decode to work. The "object-wrapper" following is a workaround, maybe an ugly one and also maybe I am missing something. Well, all that said, you have working start here:
------- 8< ---------------------------------------- class Cal( Calendar.TimeRange _time, void|string cal_subtype, void|string lang) { array(int|string) _encode() { array(int|string) a = ({ _time->unix_time(), _time->calendar()->calendar_name(), cal_subtype, lang, _time->timezone()->zoneid }); return a; }
void _decode( array(int|string) a ) { [int t, string cal_type, cal_subtype, lang, string tz] = a; object/*Calendar.* */ c = Calendar[cal_type||"ISO"]; if(lang) c = c->set_language(lang); c = c->set_timezone(tz); if(cal_subtype) { // e.g. Calendar.ISO["Day"]( Calendar.ISO.Second( time() ) ) _time = c[cal_subtype](c->Second(t)); } else { _time = c->Second(t); } }
string _sprintf() { return _time->format_ymd(); } }
int main() { object x = Calendar.ISO.Second(); Cal c = Cal(x,"Second"); string y = encode_value(c); werror("%O\n", y); sleep(3); werror("%O\n", decode_value(y)); return 0; } ---------- 8< ----------------------------------------
I kind of forgot how _encode/_decode works...
But it's probably right that there isn't anything with that index in ISO (a Second *object*).
pike-devel@lists.lysator.liu.se