flag change
This commit is contained in:
parent
16967a0d27
commit
6761867603
1 changed files with 22 additions and 22 deletions
|
@ -239,7 +239,7 @@ class FWIF {
|
||||||
}
|
}
|
||||||
|
|
||||||
private const DATETIME_FLAG_TIME = 0x40;
|
private const DATETIME_FLAG_TIME = 0x40;
|
||||||
private const DATETIME_FLAG_MILLI = 0x20;
|
private const DATETIME_FLAG_MILLI = 0x4000;
|
||||||
|
|
||||||
private const DATETIME_YEAR_SIGN = 0x40000000;
|
private const DATETIME_YEAR_SIGN = 0x40000000;
|
||||||
private const DATETIME_YEAR_MASK = 0x3FFF;
|
private const DATETIME_YEAR_MASK = 0x3FFF;
|
||||||
|
@ -265,9 +265,9 @@ class FWIF {
|
||||||
|
|
||||||
/* +--------+--------+
|
/* +--------+--------+
|
||||||
* |.YYYYYYY|YYYYYYYY|
|
* |.YYYYYYY|YYYYYYYY|
|
||||||
* |MMMMDDDD|DTVHHHHH|
|
* |MMMMDDDD|DT.HHHHH|
|
||||||
* |..mmmmmm|SSSSSSvv|
|
* |.Wmmmmmm|SSSSSSww|
|
||||||
* |vvvvvvvv| |
|
* |wwwwwwww| |
|
||||||
* +--------+--------+
|
* +--------+--------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -300,32 +300,32 @@ class FWIF {
|
||||||
|
|
||||||
if($mins > 0 || $secs > 0 || $millis > 0) {
|
if($mins > 0 || $secs > 0 || $millis > 0) {
|
||||||
$ymdfh |= self::DATETIME_FLAG_TIME;
|
$ymdfh |= self::DATETIME_FLAG_TIME;
|
||||||
$msv = 0;
|
$msw = 0;
|
||||||
$msv |= ($mins & self::DATETIME_MINS_MASK) << self::DATETIME_MINS_SHIFT;
|
$msw |= ($mins & self::DATETIME_MINS_MASK) << self::DATETIME_MINS_SHIFT;
|
||||||
$msv |= ($secs & self::DATETIME_SECS_MASK) << self::DATETIME_SECS_SHIFT;
|
$msw |= ($secs & self::DATETIME_SECS_MASK) << self::DATETIME_SECS_SHIFT;
|
||||||
|
|
||||||
if($millis > 0) {
|
if($millis > 0) {
|
||||||
$ymdfh |= self::DATETIME_FLAG_MILLI;
|
$msw |= self::DATETIME_FLAG_MILLI;
|
||||||
$msv |= ($millis & self::DATETIME_MILLI_HI_MASK) >> self::DATETIME_MILLI_HI_SHIFT;
|
$msw |= ($millis & self::DATETIME_MILLI_HI_MASK) >> self::DATETIME_MILLI_HI_SHIFT;
|
||||||
$v = $millis & self::DATETIME_MILLI_LO_MASK;
|
$w = $millis & self::DATETIME_MILLI_LO_MASK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$packed = pack('N', $ymdfh);
|
$packed = pack('N', $ymdfh);
|
||||||
if($ymdfh & self::DATETIME_FLAG_TIME) {
|
if($ymdfh & self::DATETIME_FLAG_TIME) {
|
||||||
$packed .= pack('n', $msv);
|
$packed .= pack('n', $msw);
|
||||||
if($ymdfh & self::DATETIME_FLAG_MILLI)
|
if($msw & self::DATETIME_FLAG_MILLI)
|
||||||
$packed .= chr($v);
|
$packed .= chr($w);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $packed;
|
return $packed;
|
||||||
}
|
}
|
||||||
private static function decodeDateTime($data, int $flags): DateTimeInterface {
|
private static function decodeDateTime($data, int $flags): DateTimeInterface {
|
||||||
$ymdfh = unpack('N', fread($data, 4))[1];
|
$ymdfh = unpack('N', fread($data, 4))[1];
|
||||||
$hasMsv = $ymdfh & self::DATETIME_FLAG_TIME;
|
$hasMsw = $ymdfh & self::DATETIME_FLAG_TIME;
|
||||||
$hasV = $hasMsv && ($ymdfh & self::DATETIME_FLAG_MILLI);
|
$msw = $hasMsw ? unpack('n', fread($data, 2))[1] : 0;
|
||||||
$msv = $hasMsv ? unpack('n', fread($data, 2))[1] : 0;
|
$hasW = $hasMsw && ($msw & self::DATETIME_FLAG_MILLI);
|
||||||
$v = $hasV ? ord(fgetc($data)) : 0;
|
$w = $hasW ? ord(fgetc($data)) : 0;
|
||||||
|
|
||||||
$year = ($ymdfh >> self::DATETIME_YEAR_SHIFT) & self::DATETIME_YEAR_MASK;
|
$year = ($ymdfh >> self::DATETIME_YEAR_SHIFT) & self::DATETIME_YEAR_MASK;
|
||||||
$month = ($ymdfh >> self::DATETIME_MONTH_SHIFT) & self::DATETIME_MONTH_MASK;
|
$month = ($ymdfh >> self::DATETIME_MONTH_SHIFT) & self::DATETIME_MONTH_MASK;
|
||||||
|
@ -336,13 +336,13 @@ class FWIF {
|
||||||
$year = ~$year;
|
$year = ~$year;
|
||||||
$dt = sprintf('%04d-%02d-%02dT%02d:', $year, $month, $day, $hour);
|
$dt = sprintf('%04d-%02d-%02dT%02d:', $year, $month, $day, $hour);
|
||||||
|
|
||||||
if($hasMsv) {
|
if($hasMsw) {
|
||||||
$mins = ($msv >> self::DATETIME_MINS_SHIFT) & self::DATETIME_MINS_MASK;
|
$mins = ($msw >> self::DATETIME_MINS_SHIFT) & self::DATETIME_MINS_MASK;
|
||||||
$secs = ($msv >> self::DATETIME_SECS_SHIFT) & self::DATETIME_SECS_MASK;
|
$secs = ($msw >> self::DATETIME_SECS_SHIFT) & self::DATETIME_SECS_MASK;
|
||||||
$dt .= sprintf('%02d:%02d', $mins, $secs);
|
$dt .= sprintf('%02d:%02d', $mins, $secs);
|
||||||
if($hasV) {
|
if($hasV) {
|
||||||
$millis = ($msv << self::DATETIME_MILLI_HI_SHIFT) & self::DATETIME_MILLI_HI_MASK;
|
$millis = ($msw << self::DATETIME_MILLI_HI_SHIFT) & self::DATETIME_MILLI_HI_MASK;
|
||||||
$millis |= $v;
|
$millis |= $w;
|
||||||
$dt .= sprintf('.%03d', $millis);
|
$dt .= sprintf('.%03d', $millis);
|
||||||
}
|
}
|
||||||
} else $dt .= '00:00';
|
} else $dt .= '00:00';
|
||||||
|
|
Reference in a new issue