Browse Source

fix error when retrieving options with no timezone

pull/10/head
Aaron Parecki 9 years ago
parent
commit
91bc118a50
2 changed files with 9 additions and 4 deletions
  1. +1
    -1
      controllers/controllers.php
  2. +8
    -3
      lib/helpers.php

+ 1
- 1
controllers/controllers.php View File

@ -180,7 +180,7 @@ $app->post('/post', function() use($app) {
$entry->tz_offset = tz_offset_to_seconds($params['note_tzoffset']);
$published = $date_string;
} else {
// Pebble doesn't send the date
// Pebble doesn't send the date/time/timezone
$entry->published = date('Y-m-d H:i:s');
$published = date('c'); // for the micropub post
if($location && ($timezone=get_timezone($location['latitude'], $location['longitude']))) {

+ 8
- 3
lib/helpers.php View File

@ -314,7 +314,7 @@ function query_user_frequent_options($type, $user_id) {
function query_last_eaten($user_id, $type, $content) {
$lastQ = ORM::for_table('entries')->raw_query('
SELECT published, timezone
SELECT published, timezone, tz_offset
FROM entries
WHERE user_id=:user_id
AND type=:type
@ -328,8 +328,13 @@ function query_last_eaten($user_id, $type, $content) {
$timestamp = strtotime($lastQ->published);
// If less than 8 hours ago, use relative time, otherwise show the actual time
if(time() - $timestamp > 60*60*8) {
$date = new DateTime($lastQ->published);
$date->setTimeZone(new DateTimeZone($lastQ->timezone));
if($lastQ->timezone) {
$date = new DateTime($lastQ->published);
$date->setTimeZone(new DateTimeZone($lastQ->timezone));
} else {
$iso = date_iso8601($lastQ->published, $lastQ->tz_offset);
$date = new DateTime($iso);
}
return $date->format('D, M j, g:ia');
} else {
$config = array(

Loading…
Cancel
Save