Skip to content

Daylight savings bug #284

@composerinteralia

Description

@composerinteralia

#271 seems to have introduced a daylight-savings-related bug.

If I can't fix it quickly, I may temporarily revert that PR for now.

# Run with: TZ=America/New_York
require "trilogy"

client = Trilogy.new(host: "127.0.0.1", username: "root", database: "test")
client.query_flags |= Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE

client.query("DROP TABLE IF EXISTS dst_test")
client.query("CREATE TABLE dst_test (id INT AUTO_INCREMENT PRIMARY KEY, ts DATETIME)")

# This time appears once in EDT and once in EST
client.query("INSERT INTO dst_test (ts) VALUES ('2024-11-03 01:21:54')")

time = client.query("SELECT ts FROM dst_test").to_a[0][0]

expected = Time.local(2024, 11, 3, 1, 21, 54)
puts "Trilogy result: #{time}  (utc_offset=#{time.utc_offset}, dst=#{time.dst?})"
puts "Time.local:     #{expected}  (utc_offset=#{expected.utc_offset}, dst=#{expected.dst?})"
puts "diff: #{time.to_i - expected.to_i} seconds"
raise "don't match" unless time == expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions