Skip to content

IBASE_UNIXTIME is system locale dependent #109

@mlazdans

Description

@mlazdans

php-firebird/ibase_query.c

Lines 1392 to 1393 in 23aca98

if (((type & ~1) != SQL_TYPE_TIME) && (flag & PHP_IBASE_UNIXTIME)) {
ZVAL_LONG(val, mktime(&t));

Change system locale and the output changes. It should always be UTC based.

(function() {
    $ts = 1762436759; // 2025-11-06 13:45:59 UTC

    ibase_query(
        "CREATE TABLE TTEST (
            TS TIMESTAMP
        )"
    );
    ibase_commit();

    ibase_query("INSERT INTO TTEST (TS) VALUES (?)", $ts) or die("ibase_query failed");

    dump_table_rows("TTEST");
    dump_table_rows("TTEST", null, IBASE_UNIXTIME);
})();

TZ='UTC' php script.php

array(1) {
  ["TS"]=>
  string(19) "2025-11-06 13:45:59"
}
array(1) {
  ["TS"]=>
  int(1762436759)
}

TZ='Europe/Riga' php script.php

array(1) {
  ["TS"]=>
  string(19) "2025-11-06 13:45:59"
}
array(1) {
  ["TS"]=>
  int(1762429559)
}

In database these it is stored as ISC_TIMESTAMP: 60985, 495590000 which is 13:45:59

Fixing this will introduce breaking changes. Maybe put under legacy flag or something.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions