lsolesen\pel\PelEntryTime::getValue PHP Method

getValue() public method

The timestamp held by this entry is returned in one of three formats: as a standard UNIX timestamp (default), as a fractional Julian Day Count, or as a string.
public getValue ( $type = self::UNIX_TIMESTAMP ) : integer
return integer the timestamp held by this entry in the correct form as indicated by the type argument. For {@link UNIX_TIMESTAMP} this is an integer counting the number of seconds since January 1st 1970, for {@link EXIF_STRING} this is a string of the form 'YYYY:MM:DD hh:mm:ss', and for {@link JULIAN_DAY_COUNT} this is a floating point number where the integer part denotes the day count and the fractional part denotes the time of day (0.25 means 6:00, 0.75 means 18:00).
    public function getValue($type = self::UNIX_TIMESTAMP)
    {
        switch ($type) {
            case self::UNIX_TIMESTAMP:
                $seconds = $this->convertJdToUnix($this->day_count);
                if ($seconds === false) {
                    /*
                     * We get false if the Julian Day Count is outside the range
                     * of a UNIX timestamp.
                     */
                    return false;
                } else {
                    return $seconds + $this->seconds;
                }
                break;
            case self::EXIF_STRING:
                list($year, $month, $day) = $this->convertJdToGregorian($this->day_count);
                $hours = (int) ($this->seconds / 3600);
                $minutes = (int) ($this->seconds % 3600 / 60);
                $seconds = $this->seconds % 60;
                return sprintf('%04d:%02d:%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds);
            case self::JULIAN_DAY_COUNT:
                return $this->day_count + $this->seconds / 86400;
            default:
                throw new PelInvalidArgumentException('Expected UNIX_TIMESTAMP (%d), ' . 'EXIF_STRING (%d), or ' . 'JULIAN_DAY_COUNT (%d) for $type, ' . 'got %d.', self::UNIX_TIMESTAMP, self::EXIF_STRING, self::JULIAN_DAY_COUNT, $type);
        }
    }

Usage Example

コード例 #1
0
ファイル: AsciiTest.php プロジェクト: lsolesen/pel
 function testTime()
 {
     $entry = new PelEntryTime(42, 10);
     $this->assertEquals($entry->getComponents(), 20);
     $this->assertEquals($entry->getValue(), 10);
     $this->assertEquals($entry->getValue(PelEntryTime::UNIX_TIMESTAMP), 10);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '1970:01:01 00:00:10');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2440588 + 10 / 86400);
     $this->assertEquals($entry->getText(), '1970:01:01 00:00:10');
     // Malformed Exif timestamp.
     $entry->setValue('1970!01-01 00 00 30', PelEntryTime::EXIF_STRING);
     $this->assertEquals($entry->getValue(), 30);
     $entry->setValue(2415021.75, PelEntryTime::JULIAN_DAY_COUNT);
     // This is Jan 1st 1900 at 18:00, outside the range of a UNIX
     // timestamp:
     $this->assertEquals($entry->getValue(), false);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '1900:01:01 18:00:00');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2415021.75);
     $entry->setValue('0000:00:00 00:00:00', PelEntryTime::EXIF_STRING);
     $this->assertEquals($entry->getValue(), false);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '0000:00:00 00:00:00');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 0);
     $entry->setValue('9999:12:31 23:59:59', PelEntryTime::EXIF_STRING);
     // this test will fail on 32bit machines
     $this->assertEquals($entry->getValue(), 253402300799);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '9999:12:31 23:59:59');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 5373484 + 86399 / 86400);
     // Check day roll-over for SF bug #1699489.
     $entry->setValue('2007:04:23 23:30:00', PelEntryTime::EXIF_STRING);
     $t = $entry->getValue(PelEntryTime::UNIX_TIMESTAMP);
     $entry->setValue($t + 3600);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '2007:04:24 00:30:00');
 }
All Usage Examples Of lsolesen\pel\PelEntryTime::getValue