fixed date formatting so you can use any year for events -- thanks Brian Engert!

This commit is contained in:
Ryan Walberg 2012-12-02 05:25:36 +00:00
parent fbcae57f3e
commit 092e0c65b9
3 changed files with 28 additions and 15 deletions

View file

@ -67,7 +67,6 @@ if ($action == "insert" || $action == "update") {
$eventdate = new DateTime($_GET["eventdate"]);
}
catch (Exception $e) {
echo $e->getMessage();
$eventdate = FALSE;
}
$recurring = (strtoupper($_GET["recurring"]) == "ON" ? 1 : 0);
@ -108,7 +107,7 @@ else if ($action == "edit") {
// we know this will work, see above.
$row = $stmt->fetch();
$description = $row["description"];
$eventdate = $row["eventdate"];
$eventdate = new DateTime($row["eventdate"]);
$recurring = $row["recurring"];
$systemevent = ($row["userid"] == "");
}
@ -118,7 +117,7 @@ else if ($action == "edit") {
}
else if ($action == "") {
$description = "";
$eventdate = date("m/d/Y");
$eventdate = new DateTime();
$recurring = 1;
$systemevent = 0;
}
@ -184,7 +183,13 @@ try {
$events = array();
while ($row = $stmt->fetch()) {
$row['eventdate'] = strftime($opt["date_format"], strtotime($row['eventdate']));
try {
$eventDateTime = new DateTime($row['eventdate']);
}
catch (Exception $e) {
die("There was an error with an event with datetime " . $row['eventdate']);
}
$row['eventdate'] = $eventDateTime->format($opt["date_format"]);
$events[] = $row;
}
@ -194,7 +199,7 @@ try {
$smarty->assign('action', $action);
$smarty->assign('haserror', $haserror);
$smarty->assign('events', $events);
$smarty->assign('eventdate', strftime($opt["date_format"], strtotime($eventdate)));
$smarty->assign('eventdate', $eventdate->format($opt["date_format"]));
if (isset($eventdate_error)) {
$smarty->assign('eventdate_error', $eventdate_error);
}

View file

@ -78,8 +78,9 @@ function getGlobalOptions() {
//"currency_symbol" => "€", // Euro
//"currency_symbol" => "€", // Euro alternative
/* The date format used in PHP's strftime function. */
"date_format" => "%m/%d/%Y",
/* The date format used in DateTime::format()
http://php.net/manual/en/function.date.php */
"date_format" => "m/d/Y",
/* If this is set to something other than "" then phpgiftreg will expect that
string to prefix all tables in this installation. Useful for running

View file

@ -166,7 +166,13 @@ $stmt->bindParam(2, $userid, PDO::PARAM_INT);
$stmt->execute();
$shoppees = array();
while ($row = $stmt->fetch()) {
$row['list_stamp'] = ($row['list_stamp'] == 0 ? '-' : strftime($opt["date_format"], strtotime($row['list_stamp'])));
if ($row['list_stamp'] == 0) {
$row['list_stamp'] = '-';
}
else {
$listStampDate = new DateTime($row['list_stamp']);
$row['list_stamp'] = $listStampDate->format($opt["date_format"]);
}
$shoppees[] = $row;
}
@ -201,7 +207,8 @@ $stmt->bindParam(1, $userid, PDO::PARAM_INT);
$stmt->execute();
$messages = array();
while ($row = $stmt->fetch()) {
$row['created'] = strftime($opt["date_format"], strtotime($row['created']));
$createdDateTime = new DateTime($row['created']);
$row['created'] = $createdDateTime->format($opt["date_format"]);
$messages[] = $row;
}
@ -231,32 +238,32 @@ while ($row = $stmt->fetch()) {
$days_left = -1;
if (!$row["recurring"] && (($row["ToDaysEventDate"] - $row["ToDaysToday"]) >= 0) && (($row["ToDaysEventDate"] - $row["ToDaysToday"]) <= $opt["event_threshold"])) {
$days_left = $row["ToDaysEventDate"] - $row["ToDaysToday"];
$event_date = strtotime($row["eventdate"]);
$event_date = new DateTime($row["eventdate"]);
}
else if ($row["recurring"] && (($row["ToDaysDateThisYear"] - $row["ToDaysToday"]) >= 0) && (($row["ToDaysDateThisYear"] - $row["ToDaysToday"]) <= $opt["event_threshold"])) {
$days_left = $row["ToDaysDateThisYear"] - $row["ToDaysToday"];
$event_date = strtotime($row["DateThisYear"]);
$event_date = new DateTime($row["DateThisYear"]);
}
else if ($row["recurring"] && (($row["ToDaysDateNextYear"] - $row["ToDaysToday"]) >= 0) && (($row["ToDaysDateNextYear"] - $row["ToDaysToday"]) <= $opt["event_threshold"])) {
$days_left = $row["ToDaysDateNextYear"] - $row["ToDaysToday"];
$event_date = strtotime($row["DateNextYear"]);
$event_date = new DateTime($row["DateNextYear"]);
}
if ($days_left >= 0) {
$thisevent = array(
'fullname' => $event_fullname,
'eventname' => $row['description'],
'daysleft' => $days_left,
'date' => strftime($opt["date_format"], $event_date)
'date' => $event_date->format($opt["date_format"])
);
$events[] = $thisevent;
}
}
function compareEvents($a, $b) {
if ($a[0] == $b[0])
if ($a["daysleft"] == $b["daysleft"])
return 0;
else
return ($a > $b) ? 1 : -1;
return ($a["daysleft"] > $b["daysleft"]) ? 1 : -1;
}
// i couldn't figure out another way to do this, so here goes.