1
0
mirror of https://github.com/djcb/mu.git synced 2024-06-20 06:46:50 +02:00

test-utils: add TempTz, RAII temporary timezone

This commit is contained in:
Dirk-Jan C. Binnema 2023-07-29 16:39:08 +03:00
parent 1f0342a91f
commit 766d1849ff

View File

@ -136,6 +136,28 @@ private:
const bool autodelete_;
};
/**
* Temporary (RAII) timezone
*/
struct TempTz {
TempTz(const char* tz) {
if (timezone_available(tz))
old_tz_ = set_tz(tz);
else
old_tz_ = {};
mu_debug("timezone '{}' {}available", tz, old_tz_ ? "": "not");
}
~TempTz() {
if (old_tz_) {
mu_debug("reset timezone to '{}'", old_tz_);
set_tz(old_tz_);
}
}
bool available() const { return !!old_tz_; }
private:
const char *old_tz_{};
};
} // namepace Mu