flag change

This commit is contained in:
flash 2020-12-26 04:38:51 +00:00
parent 16967a0d27
commit 6761867603

View file

@ -239,7 +239,7 @@ class FWIF {
}
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_MASK = 0x3FFF;
@ -265,9 +265,9 @@ class FWIF {
/* +--------+--------+
* |.YYYYYYY|YYYYYYYY|
* |MMMMDDDD|DTVHHHHH|
* |..mmmmmm|SSSSSSvv|
* |vvvvvvvv| |
* |MMMMDDDD|DT.HHHHH|
* |.Wmmmmmm|SSSSSSww|
* |wwwwwwww| |
* +--------+--------+
*/
@ -300,32 +300,32 @@ class FWIF {
if($mins > 0 || $secs > 0 || $millis > 0) {
$ymdfh |= self::DATETIME_FLAG_TIME;
$msv = 0;
$msv |= ($mins & self::DATETIME_MINS_MASK) << self::DATETIME_MINS_SHIFT;
$msv |= ($secs & self::DATETIME_SECS_MASK) << self::DATETIME_SECS_SHIFT;
$msw = 0;
$msw |= ($mins & self::DATETIME_MINS_MASK) << self::DATETIME_MINS_SHIFT;
$msw |= ($secs & self::DATETIME_SECS_MASK) << self::DATETIME_SECS_SHIFT;
if($millis > 0) {
$ymdfh |= self::DATETIME_FLAG_MILLI;
$msv |= ($millis & self::DATETIME_MILLI_HI_MASK) >> self::DATETIME_MILLI_HI_SHIFT;
$v = $millis & self::DATETIME_MILLI_LO_MASK;
$msw |= self::DATETIME_FLAG_MILLI;
$msw |= ($millis & self::DATETIME_MILLI_HI_MASK) >> self::DATETIME_MILLI_HI_SHIFT;
$w = $millis & self::DATETIME_MILLI_LO_MASK;
}
}
$packed = pack('N', $ymdfh);
if($ymdfh & self::DATETIME_FLAG_TIME) {
$packed .= pack('n', $msv);
if($ymdfh & self::DATETIME_FLAG_MILLI)
$packed .= chr($v);
$packed .= pack('n', $msw);
if($msw & self::DATETIME_FLAG_MILLI)
$packed .= chr($w);
}
return $packed;
}
private static function decodeDateTime($data, int $flags): DateTimeInterface {
$ymdfh = unpack('N', fread($data, 4))[1];
$hasMsv = $ymdfh & self::DATETIME_FLAG_TIME;
$hasV = $hasMsv && ($ymdfh & self::DATETIME_FLAG_MILLI);
$msv = $hasMsv ? unpack('n', fread($data, 2))[1] : 0;
$v = $hasV ? ord(fgetc($data)) : 0;
$hasMsw = $ymdfh & self::DATETIME_FLAG_TIME;
$msw = $hasMsw ? unpack('n', fread($data, 2))[1] : 0;
$hasW = $hasMsw && ($msw & self::DATETIME_FLAG_MILLI);
$w = $hasW ? ord(fgetc($data)) : 0;
$year = ($ymdfh >> self::DATETIME_YEAR_SHIFT) & self::DATETIME_YEAR_MASK;
$month = ($ymdfh >> self::DATETIME_MONTH_SHIFT) & self::DATETIME_MONTH_MASK;
@ -336,13 +336,13 @@ class FWIF {
$year = ~$year;
$dt = sprintf('%04d-%02d-%02dT%02d:', $year, $month, $day, $hour);
if($hasMsv) {
$mins = ($msv >> self::DATETIME_MINS_SHIFT) & self::DATETIME_MINS_MASK;
$secs = ($msv >> self::DATETIME_SECS_SHIFT) & self::DATETIME_SECS_MASK;
if($hasMsw) {
$mins = ($msw >> self::DATETIME_MINS_SHIFT) & self::DATETIME_MINS_MASK;
$secs = ($msw >> self::DATETIME_SECS_SHIFT) & self::DATETIME_SECS_MASK;
$dt .= sprintf('%02d:%02d', $mins, $secs);
if($hasV) {
$millis = ($msv << self::DATETIME_MILLI_HI_SHIFT) & self::DATETIME_MILLI_HI_MASK;
$millis |= $v;
$millis = ($msw << self::DATETIME_MILLI_HI_SHIFT) & self::DATETIME_MILLI_HI_MASK;
$millis |= $w;
$dt .= sprintf('.%03d', $millis);
}
} else $dt .= '00:00';