aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/datetime/date-time.h3
-rw-r--r--src/date-time.cpp18
2 files changed, 16 insertions, 5 deletions
diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h
index 7e19a9d..ea9ea36 100644
--- a/include/datetime/date-time.h
+++ b/include/datetime/date-time.h
@@ -37,10 +37,11 @@ class DateTime
{
public:
static DateTime NowLocal();
+ static DateTime Local(time_t);
static DateTime Local(int year, int month, int day, int hour, int minute, double seconds);
DateTime();
- explicit DateTime(time_t t);
+ DateTime(GTimeZone* tz, time_t t);
DateTime(GTimeZone* tz, GDateTime* dt);
DateTime(GTimeZone* tz, int year, int month, int day, int hour, int minute, double seconds);
DateTime& operator=(const DateTime& in);
diff --git a/src/date-time.cpp b/src/date-time.cpp
index 54601d0..4930bf6 100644
--- a/src/date-time.cpp
+++ b/src/date-time.cpp
@@ -65,13 +65,13 @@ DateTime& DateTime::operator+=(const std::chrono::seconds& seconds)
return (*this = add_full(0, 0, 0, 0, 0, seconds.count()));
}
-DateTime::DateTime(time_t t)
+DateTime::DateTime(GTimeZone* gtz, time_t t)
{
- auto gtz = g_time_zone_new_local();
- auto gdt = g_date_time_new_from_unix_local(t);
+ auto utc = g_date_time_new_from_unix_utc(t);
+ auto gdt = g_date_time_to_timezone (utc, gtz);
reset(gtz, gdt);
- g_time_zone_unref(gtz);
g_date_time_unref(gdt);
+ g_date_time_unref(utc);
}
DateTime DateTime::NowLocal()
@@ -84,6 +84,16 @@ DateTime DateTime::NowLocal()
return dt;
}
+DateTime DateTime::Local(time_t t)
+{
+ auto gtz = g_time_zone_new_local();
+ auto gdt = g_date_time_new_from_unix_local(t);
+ DateTime dt(gtz, gdt);
+ g_time_zone_unref(gtz);
+ g_date_time_unref(gdt);
+ return dt;
+}
+
DateTime DateTime::Local(int year, int month, int day, int hour, int minute, double seconds)
{
auto gtz = g_time_zone_new_local();