clx::date_time in vc6 おぼえがき
仕事で使うよさげな時間クラスを探してclxを使おうかなと思い始めた
まあ一発で通らなかったので色々修正したメモ
しかし需要がなさそうなネタである
std::time?
std::mktimeとかstd::time_tとかstd::difftimeとかがstd名前空間にないので
全部mktimeとかに置き換える
clx/config.hあたりに追加。
#if defined(_MSC_VER) && (_MSC_VER == 1200) typedef time_t clx_time_t; typedef size_t clx_size_t; #else typedef std::time_t clx_time_t; typedef std::size_t clx_size_t; #endif
nowがUTCしか返してくれないんだけど
こういう問題があります:VC6 の関数テンプレートのバグにハマる
てなわけで、この現状だと動かないんで、修正
clx/date_time.h
template <int TimeZone> void now(struct tm *result) { std::time_t t = std::time(NULL); xlocaltime(&t, result); } template <> void now<CLX_TZ_UTC>(struct tm *result) { std::time_t t = std::time(NULL); xgmtime(&t, result); }
こんな感じ
/* VC6はテンプレートにバグがあるため、VC6でも動くように修正を行う 参考:http://www.fides.dti.ne.jp/~oka-t/cpplab-vc6-func-template-bug.html */ template <int TimeZone> class now { public: void operator()(struct tm *result) { #if defined(_MSC_VER) && (_MSC_VER == 1200) clx_time_t t = time(NULL); #else clx_time_t t = std::time(NULL); #endif xgmtime(&t, result); } }; template <> class now<CLX_TZ_LOCAL> { public: void operator()(struct tm *result) { clx_time_t t = time(NULL); xlocaltime(&t, result); } };
関数オブジェクト化しちゃったんで使う方も変える
std::use_facet
コンパイルできなかったんでちょこっと修正したんだけどこれは未チェック
clx/win32/date_time.h(153)
#if defined(_MSC_VER) && (_MSC_VER == 1200) const std::time_get<char>& tg = std::use_facet<std::time_get<char> >(std::locale(), NULL, true); #else const std::time_get<char>& tg = std::use_facet<std::time_get<char> >(std::locale()); #endif
結論
VC6爆発しろ!