You are here

function flot_handler_field_datapoint::format_date in Flot 6

Same name and namespace in other branches
  1. 7 flot_views/views/flot_handler_field_datapoint.inc \flot_handler_field_datapoint::format_date()

Custom date formatter for achieving date granularity between 1 hour and 12 hours (AM/PM).

1 call to flot_handler_field_datapoint::format_date()
flot_handler_field_datapoint::pre_render in views/flot_handler_field_datapoint.inc
Optional method that allows the data source to determine axis bounds.

File

views/flot_handler_field_datapoint.inc, line 261

Class

flot_handler_field_datapoint

Code

function format_date($timestamp, $format) {
  switch ($format) {
    case 'Y-m-d-3':
    case 'Y-m-d-6':
      $base = strtotime(format_date($timestamp, 'custom', 'Y-m-d'));
      $hour = format_date($timestamp, 'custom', 'H');
      $hours = array(
        'Y-m-d-3' => array(
          3,
          6,
          9,
          12,
          15,
          18,
          21,
          24,
        ),
        'Y-m-d-6' => array(
          6,
          12,
          18,
          24,
        ),
      );
      foreach ($hours[$format] as $slot) {
        if ($hour < $slot) {
          $formatted = strtotime("+{$slot} hours", $base);
          break;
        }
      }
      return format_date($formatted, 'custom', 'Y-m-d-H');
    default:
      return format_date($timestamp, 'custom', $format);
  }
}