aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/date-time.cpp60
-rw-r--r--src/planner-month.cpp4
2 files changed, 44 insertions, 20 deletions
diff --git a/src/date-time.cpp b/src/date-time.cpp
index 4176d06..689688c 100644
--- a/src/date-time.cpp
+++ b/src/date-time.cpp
@@ -39,6 +39,15 @@ DateTime::DateTime(GTimeZone* gtz, GDateTime* gdt)
reset(gtz, gdt);
}
+DateTime::DateTime(GTimeZone* gtz, int year, int month, int day, int hour, int minute, double seconds)
+{
+ g_return_if_fail(gtz!=nullptr);
+
+ auto gdt = g_date_time_new(gtz, year, month, day, hour, minute, seconds);
+ reset(gtz, gdt);
+ g_date_time_unref(gdt);
+}
+
DateTime& DateTime::operator=(const DateTime& that)
{
m_tz = that.m_tz;
@@ -65,13 +74,11 @@ DateTime DateTime::NowLocal()
return dt;
}
-DateTime DateTime::Local(int year, int month, int day, int hour, int minute, int seconds)
+DateTime DateTime::Local(int year, int month, int day, int hour, int minute, double seconds)
{
auto gtz = g_time_zone_new_local();
- auto gdt = g_date_time_new(gtz, year, month, day, hour, minute, seconds);
- DateTime dt(gtz, gdt);
+ DateTime dt(gtz, year, month, day, hour, minute, seconds);
g_time_zone_unref(gtz);
- g_date_time_unref(gdt);
return dt;
}
@@ -85,33 +92,50 @@ DateTime DateTime::to_timezone(const std::string& zone) const
return dt;
}
+DateTime DateTime::end_of_day() const
+{
+ g_assert(is_set());
+
+ return add_days(1).start_of_day().add_full(0,0,0,0,0,-1);
+}
+
+DateTime DateTime::end_of_month() const
+{
+ g_assert(is_set());
+
+ return add_full(0,1,0,0,0,0).start_of_month().add_full(0,0,0,0,0,-1);
+}
+
+DateTime DateTime::start_of_month() const
+{
+ g_assert(is_set());
+
+ int year=0, month=0, day=0;
+ ymd(year, month, day);
+ return DateTime(m_tz.get(), year, month, 1, 0, 0, 0);
+}
+
DateTime DateTime::start_of_day() const
{
g_assert(is_set());
- int y=0, m=0, d=0;
- ymd(y, m, d);
- auto gdt = g_date_time_new(m_tz.get(), y, m, d, 0, 0, 0);
- DateTime dt(m_tz.get(), gdt);
- g_date_time_unref(gdt);
- return dt;
+ int year=0, month=0, day=0;
+ ymd(year, month, day);
+ return DateTime(m_tz.get(), year, month, day, 0, 0, 0);
}
DateTime DateTime::start_of_minute() const
{
g_assert(is_set());
- int y=0, m=0, d=0;
- ymd(y, m, d);
- auto gdt = g_date_time_new(m_tz.get(), y, m, d, hour(), minute(), 0);
- DateTime dt(m_tz.get(), gdt);
- g_date_time_unref(gdt);
- return dt;
+ int year=0, month=0, day=0;
+ ymd(year, month, day);
+ return DateTime(m_tz.get(), year, month, day, hour(), minute(), 0);
}
-DateTime DateTime::add_full(int years, int months, int days, int hours, int minutes, double seconds) const
+DateTime DateTime::add_full(int year, int month, int day, int hour, int minute, double seconds) const
{
- auto gdt = g_date_time_add_full(get(), years, months, days, hours, minutes, seconds);
+ auto gdt = g_date_time_add_full(get(), year, month, day, hour, minute, seconds);
DateTime dt(m_tz.get(), gdt);
g_date_time_unref(gdt);
return dt;
diff --git a/src/planner-month.cpp b/src/planner-month.cpp
index fd8a568..cdae26f 100644
--- a/src/planner-month.cpp
+++ b/src/planner-month.cpp
@@ -32,8 +32,8 @@ MonthPlanner::MonthPlanner(const std::shared_ptr<RangePlanner>& range_planner,
m_range_planner(range_planner)
{
month().changed().connect([this](const DateTime& m){
- auto month_begin = m.start_of_day().add_full(0, 0, -(m.day_of_month()-1), 0, 0, 0);
- auto month_end = month_begin.add_full(0, 1, 0, 0, 0, -0.1);
+ auto month_begin = m.start_of_month();
+ auto month_end = m.end_of_month();
g_debug("PlannerMonth %p setting calendar month range: [%s..%s]", this, month_begin.format("%F %T").c_str(), month_end.format("%F %T").c_str());
m_range_planner->range().set(std::pair<DateTime,DateTime>(month_begin,month_end));
});