2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "kdm_timing_panel.h"
22 #include <wx/datectrl.h>
23 #include <wx/timectrl.h>
25 KDMTimingPanel::KDMTimingPanel (wxWindow* parent)
26 : wxPanel (parent, wxID_ANY)
28 wxFlexGridSizer* table = new wxFlexGridSizer (6, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
29 add_label_to_sizer (table, this, _("From"), true);
32 _from_date = new wxDatePickerCtrl (this, wxID_ANY, from);
33 table->Add (_from_date, 1, wxEXPAND);
34 _from_time = new wxTimePickerCtrl (this, wxID_ANY, from);
35 table->Add (_from_time, 1, wxEXPAND);
37 add_label_to_sizer (table, this, _("until"), true);
40 to.Add (wxDateSpan (0, 0, 1, 0));
41 _until_date = new wxDatePickerCtrl (this, wxID_ANY, to);
42 table->Add (_until_date, 1, wxEXPAND);
43 _until_time = new wxTimePickerCtrl (this, wxID_ANY, to);
44 table->Add (_until_time, 1, wxEXPAND);
49 boost::posix_time::ptime
50 KDMTimingPanel::from () const
52 return posix_time (_from_date, _from_time);
55 boost::posix_time::ptime
56 KDMTimingPanel::posix_time (wxDatePickerCtrl* date_picker, wxTimePickerCtrl* time_picker)
58 wxDateTime const date = date_picker->GetValue ();
59 wxDateTime const time = time_picker->GetValue ();
60 return boost::posix_time::ptime (
61 boost::gregorian::date (date.GetYear(), date.GetMonth() + 1, date.GetDay()),
62 boost::posix_time::time_duration (time.GetHour(), time.GetMinute(), time.GetSecond())
66 boost::posix_time::ptime
67 KDMTimingPanel::until () const
69 return posix_time (_until_date, _until_time);