Skip to content

datetimeoffset not preserving offset #558

@devmitchell

Description

@devmitchell

I'm in the process of transitioning a column to use the datetimeoffset datatype. However, the datatype keeps getting set to UTC, having its offset ignored. Here are a couple of interesting observations that may or may not help with this:

  1. The schema.rb file never shows the right datatype.

    The migration file specifies the new type, and the migrations succeed.

    # Migration file
    t.datetimeoffset :special_datetime

    Checking the database, the type is as it should be: datetimeoffset(7). But the schema.rb file never reflects this.

    # schema.rb
    t.datetime "special_datetime", precision: 7
  2. The model types reference datetime.

    When just checking the model in a rails console, it shows the field as datetime:

    TestModel(id: integer, special_datetime: datetime, created_at: datetime, updated_at: datetime) 
  3. Tiny TDS works.

    2.3.1 :005 > client = TinyTds::Client.new host: '192.168.63.155', username: 'user123', password: 'somethingspecial', database: 'project_development'
     => #<TinyTds::Client:0x007fa681d942f0 @query_options={:as=>:hash, :symbolize_keys=>false, :cache_rows=>true, :timezone=>:local, :empty_sets=>true}> 
    2.3.1 :006 > result = client.execute('update test_models set special_datetime = "2017-02-06 23:08:18 +06:00" where 1 = 1')
     => #<TinyTds::Result:0x007fa681d75bc0 @query_options={:as=>:hash, :symbolize_keys=>false, :cache_rows=>true, :timezone=>:local, :empty_sets=>true}> 

    I can find that this succeeded as it should when I check out the database.

  4. The SQL getting generated never mentions the offset.

    When I check the SQL being generated in a workflow, the data being referenced to ultimately be part of the SQL has no offset: ["special_datetime", "02-06-2017 23:46:18.0"]

Under the Hood

  • activerecord (5.0.0.1)
  • activerecord-sqlserver-adapter (5.0.3)
  • tiny_tds (1.1.0)

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