<commit_before>require 'test_helper'
require 'db/mssql'

class MSSQLDateTimeTypesTest < Test::Unit::TestCase

  TABLE_DEFINITION = "CREATE TABLE date_and_times " <<
    "( [id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY, [datetime] DATETIME )"

  @@default_timezone = ActiveRecord::Base.default_timezone

  def self.startup
    super
    ActiveRecord::Base.default_timezone = :local
    ActiveRecord::Base.connection.execute TABLE_DEFINITION
    # ActiveRecord::Base.logger.level = Logger::DEBUG
  end

  def self.shutdown
    # ActiveRecord::Base.logger.level = Logger::WARN
    ActiveRecord::Base.connection.execute "DROP TABLE date_and_times"
    ActiveRecord::Base.default_timezone = @@default_timezone
    super
  end

  class DateAndTime < ActiveRecord::Base; end

  def test_datetime
    # January 1, 1753, through December 31, 9999 + 00:00:00 through 23:59:59.997
    datetime = DateTime.parse('2012-12-21T21:11:01').to_time
    model = DateAndTime.create! :datetime => datetime
    assert_datetime_equal datetime, model.reload.datetime
  end if ar_version('3.0')

  if ActiveRecord::Base.connection.sqlserver_version >= '2008'

    # 2008 Date and Time: http://msdn.microsoft.com/en-us/library/ff848733.aspx

    TABLE_DEFINITION.replace "CREATE TABLE date_and_times (" <<
      "[id] int NOT NULL IDENTITY(1, 1)," <<
      "[datetime] DATETIME, " <<
      "[date] DATE, " <<
      "[datetime2] DATETIME2, " <<
      "[datetime25] DATETIME2(5), " <<<commit_msg>reproducing issue #444 (invalid rescue syntax at MSSQL's `string_to_time`)<commit_after>require 'test_helper'
require 'db/mssql'

class MSSQLDateTimeTypesTest < Test::Unit::TestCase

  TABLE_DEFINITION = "CREATE TABLE date_and_times " <<
    "( [id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY, [datetime] DATETIME )"

  @@default_timezone = ActiveRecord::Base.default_timezone

  def self.startup
    super
    ActiveRecord::Base.default_timezone = :local
    ActiveRecord::Base.connection.execute TABLE_DEFINITION
    # ActiveRecord::Base.logger.level = Logger::DEBUG
  end

  def self.shutdown
    # ActiveRecord::Base.logger.level = Logger::WARN
    ActiveRecord::Base.connection.execute "DROP TABLE date_and_times"
    ActiveRecord::Base.default_timezone = @@default_timezone
    super
  end

  class DateAndTime < ActiveRecord::Base; end

  def test_datetime
    # January 1, 1753, through December 31, 9999 + 00:00:00 through 23:59:59.997
    datetime = DateTime.parse('2012-12-21T21:11:01').to_time
    model = DateAndTime.create! :datetime => datetime
    assert_datetime_equal datetime, model.reload.datetime
  end if ar_version('3.0')

  if ActiveRecord::Base.connection.sqlserver_version >= '2008'

    # 2008 Date and Time: http://msdn.microsoft.com/en-us/library/ff848733.aspx

    TABLE_DEFINITION.replace "CREATE TABLE date_and_times (" <<
      "[id] int NOT NULL IDENTITY(1, 1)," <<
      "[datetime] DATETIME DEFAULT 0, " <<
      "[date] DATE, " <<
      "[datetime2] DATETIME2, " <<
      "[datetime25] DATETIME2(5), " <<
{'fraction_non_alphanumeric': 0.12179700499168053, 'fraction_numerical': 0.045257903494176376, 'mean_word_length': 4.173838209982788, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4010934', 'n_tokens_mistral': 1080, 'n_tokens_neox': 945, 'n_words': 208}