From 99b67b42f6844701667fe01b5d781d03ce299d59 Mon Sep 17 00:00:00 2001
From: Christian Wieninger <cwieninger (at) gmx (dot) de>
Date: Wed, 16 Jan 2008 20:39:19 +0100
Subject: - fix for #418 via DatePicker

---
 epgsearch.cpp         | 27 ---------------------------
 pages/edit_timer.ecpp | 10 ++++++----
 tools.cpp             | 29 +++++++++++++++++++++++++++++
 tools.h               |  2 ++
 4 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/epgsearch.cpp b/epgsearch.cpp
index 622ef21..d22c636 100644
--- a/epgsearch.cpp
+++ b/epgsearch.cpp
@@ -320,17 +320,6 @@ string SearchTimer::StopTimeFormatted()
 	return FormatDateTime(tr("%I:%M %p"), stop);
 }
 
-// format is in datepicker format ('mm' for month, 'dd' for day, 'yyyy' for year)
-string DatePickerToC(time_t date, string const& format)
-{
-	if (date == 0) return "";
-	string cformat = format;
-	cformat = StringReplace(cformat, "mm", "%m");
-	cformat = StringReplace(cformat, "dd", "%d");
-	cformat = StringReplace(cformat, "yyyy", "%Y");
-	return FormatDateTime(cformat.c_str(), date);
-}
-
 string SearchTimer::UseAsSearchTimerFrom(string const& format)
 {
 	return DatePickerToC(m_useAsSearchTimerFrom, format);
@@ -341,22 +330,6 @@ string SearchTimer::UseAsSearchTimerTil(string const& format)
 	return DatePickerToC(m_useAsSearchTimerTil, format);
 }
 
-time_t GetDateFromDatePicker(std::string const& datestring, std::string const& format)
-{
-	if (datestring.empty()) 
-		return 0;
-	int year = lexical_cast< int >(datestring.substr(format.find("yyyy"), 4));
-	int month = lexical_cast< int >(datestring.substr(format.find("mm"), 2));
-	int day = lexical_cast< int >(datestring.substr(format.find("dd"), 2));
-	struct tm tm_r;
-	tm_r.tm_year = year - 1900;
-	tm_r.tm_mon = month -1;
-	tm_r.tm_mday = day;
-	tm_r.tm_hour = tm_r.tm_min = tm_r.tm_sec = 0;
-	tm_r.tm_isdst = -1; // makes sure mktime() will determine the correct DST setting
-	return mktime(&tm_r);
-}
-
 void SearchTimer::SetUseAsSearchTimerFrom(std::string const& datestring, std::string const& format)
 {
 	m_useAsSearchTimerFrom = GetDateFromDatePicker(datestring, format);
diff --git a/pages/edit_timer.ecpp b/pages/edit_timer.ecpp
index d5cef43..c269055 100644
--- a/pages/edit_timer.ecpp
+++ b/pages/edit_timer.ecpp
@@ -23,7 +23,7 @@ using namespace vdrlive;
 	tChannelID channel;
 	bool active = true;
 	string title = "";
-	string day = "";
+	string date = "";
 	bool wday_mon = false;
 	bool wday_tue = false;
 	bool wday_wed = false;
@@ -77,7 +77,9 @@ cTimer* timer;
 			message = tr("Please set a title for the timer!");
 		else
 		{
-			LiveTimerManager().UpdateTimer( timer, flags, channel, weekdays, day, start, stop, priority, lifetime, title, aux );
+			time_t tdate = GetDateFromDatePicker(date, tr("mm/dd/yyyy"));
+			string sdate = DatePickerToC(tdate, "yyyy-mm-dd");
+			LiveTimerManager().UpdateTimer( timer, flags, channel, weekdays, sdate, start, stop, priority, lifetime, title, aux );
 			return reply.redirect(!edit_timerreferer.empty()?edit_timerreferer:"timers.html");
 		}
 	}
@@ -107,7 +109,7 @@ cTimer* timer;
 		active = timer->Flags() & tfActive;
 		channel = timer->Channel()->GetChannelID();
 		title = timer->File() ? timer->File() : "";
-		day = timer->Day() ? FormatDateTime( "%d", timer->Day() ) : "";
+		date = timer->Day() ? DatePickerToC(timer->Day(), tr("mm/dd/yyyy")) : "";
 		wday_mon = timer->WeekDays() & 0x01;
 		wday_tue = timer->WeekDays() & 0x02;
 		wday_wed = timer->WeekDays() & 0x04;
@@ -170,7 +172,7 @@ cTimer* timer;
 
 					<tr>
 						<td class="label leftcol"><div class="withmargin"><$ trVDR("Day") $>:</div></td>
-						<td class="rightcol"><input type="text" name="day" value="<$ day $>" size="2" maxlength="2" /></td>
+						<td class="rightcol"><input id="date" name="date" type="text" class="DatePicker" value="<$ date $>" /></td>
 					</tr>
 
 					<tr>
diff --git a/tools.cpp b/tools.cpp
index 3851808..1839f6b 100644
--- a/tools.cpp
+++ b/tools.cpp
@@ -242,4 +242,33 @@ string GetXMLValue( std::string const& xml, std::string const& element )
 	return xml.substr(startPos + start.size(), endPos - startPos - start.size());
 }
 
+// return the time value as time_t from <datestring> formatted with <format>
+time_t GetDateFromDatePicker(std::string const& datestring, std::string const& format)
+{
+	if (datestring.empty()) 
+		return 0;
+	int year = lexical_cast< int >(datestring.substr(format.find("yyyy"), 4));
+	int month = lexical_cast< int >(datestring.substr(format.find("mm"), 2));
+	int day = lexical_cast< int >(datestring.substr(format.find("dd"), 2));
+	struct tm tm_r;
+	tm_r.tm_year = year - 1900;
+	tm_r.tm_mon = month -1;
+	tm_r.tm_mday = day;
+	tm_r.tm_hour = tm_r.tm_min = tm_r.tm_sec = 0;
+	tm_r.tm_isdst = -1; // makes sure mktime() will determine the correct DST setting
+	return mktime(&tm_r);
+}
+
+// format is in datepicker format ('mm' for month, 'dd' for day, 'yyyy' for year)
+std::string DatePickerToC(time_t date, std::string const& format)
+{
+	if (date == 0) return "";
+	std::string cformat = format;
+	cformat = StringReplace(cformat, "mm", "%m");
+	cformat = StringReplace(cformat, "dd", "%d");
+	cformat = StringReplace(cformat, "yyyy", "%Y");
+	return FormatDateTime(cformat.c_str(), date);
+}
+
+
 } // namespace vdrlive
diff --git a/tools.h b/tools.h
index bb1798b..46ce8ca 100644
--- a/tools.h
+++ b/tools.h
@@ -38,6 +38,8 @@ time_t GetTimeT(std::string timestring);
 std::string ExpandTimeString(std::string timestring);
 std::string StringUrlEncode( std::string const& input );
 std::string GetXMLValue( std::string const& xml, std::string const& element );
+time_t GetDateFromDatePicker(std::string const& datestring, std::string const& format);
+ std::string DatePickerToC(time_t date, std::string const& format);
 
 struct bad_lexical_cast: std::runtime_error 
 {
-- 
cgit v1.2.3