On Tue, 28 Oct 2003 15:47:31 -0700
"Jeff Garland"
On Mon, 27 Oct 2003 14:36:57 +0100, Erik Thiele wrote
hi.
i am trying to convert between UTC and CEST/CET (Europe/Berlin)
i don't find documentation or suitable functions in the Wiki, the examples or the documentation.
Eric -
The local time conversion code is still experimental which is why it is undocumented.
i see :-) i now use c_local_adjustor, and rewrote my code. it now always uses utc and converts only in one direction. utc->local. which is what the c_local_adjustor can do.
As I said, this is experimental code and I think this approach has proven to be rather cumbersome. I'm working on a 'dynamic timezone' class that will provide the ability to construct zone and offset data at runtime instead of using traits for timezone configurations. This won't be in the 1.31 release, however...
something like: ptime a,b,c,d; timezone_converter zc ("CET"); // calls setzone("CET"); timezone_converter_result_t result; zc.local_to_utc(a, b, result); // converts "CET" a to utc b. function return value is "void" // result is enum "unique", "undefined", "double_possibilities", choose // better words of course :) i.e. the hour that does not exist results in b unchanged, but result==undefined. the hour that exists twice results in b being the defaulting one of the two (see below) and result==double_possibilities a normal time does result==unique. zc.setzone("Europe/Berlin"); the returned value in the conversion routine when there are double_possibilities should be determined by the set timezone as follows: zc.setzone("CET"); // return the utc corresponding to the given local time in winter time zc.setzone("CEST"); // return the utc corresponding to the given local time in summer time but of course in both cases result==double_possibilities. then of course one could also have shortcuts like: ptime local_to_utc(const ptime local); // throws exception if "undefined", returns default if "double_possibilities" ******** the utc_to_local function is quite interesting: void time_converter::utc_to_local(ptime &utc, ptime &localtime, time_zone &adjzone); see, even though the time_converter has a setzone("CET"); still the adjzone is returned. this i think could be interesting because: zc.setzone("CET"); // there is implicit conversion char* -> time_zone zc.setzone("CEST"); // we only use utc_to_local, so this has the same effect than "CET". timezone myzone; zc.utc_to_local(a, b, myzone); if (myzone == timezone("CET")) cout << "hey it's winter\n"; else if (myzone == timezone("CEST")) cout << "hey, it's summer\n"; else fatal("internal impossibility"); if (myzone.timekind()==time_zone::SUMMERTIME) if (myzone.timekind()==time_zone::WINTERTIME) if (myzone.timekind()==time_zone::HIGHSUMMERTIME) // stupid rules ... if (myzone.timekind()==time_zone::NORMALTIME) // there exists no summer,winter,etc. ****** timezone baba ("CET"); timezone lulu ("Europe/Berlin"); // defaults to default-time, i.e. winter time timezone kuku ("CEST"); assert (baba==lulu); assert (lulu != kuku); ****** there are major design questions in timezone stuff. for example, is CET == CEST.. as you see above i decided they are not equal. maybe my ideas are of help. cu & keep up good work erik -- Erik Thiele