Exemplo n.º 1
0
 /**
  * Return this object with client-facing fields and hypermedia, ready for output
  */
 public function getOutputView(Request $request, $verbose = false)
 {
     $item = array();
     if ($verbose) {
         $fields = $this->getVerboseFields();
     } else {
         $fields = $this->getDefaultFields();
     }
     $fields = array_merge($fields, $this->getSubResources());
     // special handling for dates
     if ($this->event_tz_place != '' && $this->event_tz_cont != '') {
         $tz = $this->event_tz_cont . '/' . $this->event_tz_place;
     } else {
         $tz = 'UTC';
     }
     foreach ($fields as $output_name => $name) {
         $value = $this->{$name};
         // override if it is a date
         if (substr($output_name, -5) == '_date' && !empty($value)) {
             $value = Timezone::formattedEventDatetimeFromUnixtime($value, $tz, 'c');
         }
         $item[$output_name] = $value;
     }
     return $item;
 }
Exemplo n.º 2
0
 public function transformResults($results, $verbose)
 {
     $fields = $verbose ? $this->getVerboseFields() : $this->getDefaultFields();
     $retval = array();
     // format results to only include named fields
     foreach ($results as $row) {
         $entry = array();
         foreach ($fields as $key => $value) {
             // special handling for dates
             if (substr($key, -5) == '_date' && !empty($row[$value])) {
                 if ($row['event_tz_place'] != '' && $row['event_tz_cont'] != '') {
                     $tz = $row['event_tz_cont'] . '/' . $row['event_tz_place'];
                 } else {
                     $tz = 'UTC';
                 }
                 $entry[$key] = Timezone::formattedEventDatetimeFromUnixtime($row[$value], $tz, 'c');
             } else {
                 if (array_key_exists($value, $row)) {
                     $entry[$key] = $row[$value];
                 } else {
                     $entry[$key] = null;
                 }
             }
         }
         $retval[] = $entry;
     }
     return $retval;
 }
Exemplo n.º 3
0
 /**
  * Ensures that a correct format will be returned from given timestamps for a particular timezone
  *
  * @param integer $timestamp Unix Timestamp
  * @param string  $timezone  Timezone
  * @param string  $format    Date format
  * @param string  $expected  Expected output
  *
  * @return void
  *
  * @nottest
  * @dataProvider formattedDateProvider
  */
 public function datesAreFormattedAsExpected($timestamp, $timezone, $format, $expected)
 {
     $this->markTestSkipped('Test is brittle and fails or passes based on timezone changes.');
     $this->assertEquals($expected, \Timezone::formattedEventDatetimeFromUnixtime($timestamp, $timezone, $format));
 }