<commit_before>require 'spec_helper'

describe Cdx::Api::LocalTimeZoneConversion do
  include Cdx::Api::LocalTimeZoneConversion

  describe 'keeps strings and integers unchanged' do
    it { expect(convert_timezone_if_date("1")).to eq "1" }
    it { expect(convert_timezone_if_date("100")).to eq "100" }
    it { expect(convert_timezone_if_date("foo")).to eq "foo" }
  end

  describe 'assumes local timezone' do
    it { expect(convert_timezone_if_date("1990-10-01")).to eq local(1990, 10, 1, 00, 00, 00) }
    it { expect(convert_timezone_if_date("1990-10-01T02:30:24")).to eq local(1990, 10, 1, 02, 30, 24) }
    it { expect(convert_timezone_if_date("1990-01-01T02:30:24Z-03:00")).to eq "1990-01-01T02:30:24Z-03:00" }
  end

  def local(*args)
    Time.zone.local(*args).iso8601
  end
end<commit_msg>Testing conversion when there is not timezone<commit_after>require 'spec_helper'

describe Cdx::Api::LocalTimeZoneConversion do
  include Cdx::Api::LocalTimeZoneConversion

  describe 'converting integers and strings' do
    it { expect(convert_timezone_if_date("1")).to eq "1" }
    it { expect(convert_timezone_if_date("100")).to eq "100" }
    it { expect(convert_timezone_if_date("foo")).to eq "foo" }
  end

  describe 'converting dates' do
    context 'when there is a local timezone' do
      before { Time.zone = ActiveSupport::TimeZone["Asia/Seoul"] }
      it { expect(convert_timezone_if_date("1990-10-01")).to eq local(1990, 10, 1, 00, 00, 00) }
      it { expect(convert_timezone_if_date("1990-10-01T02:30:24")).to eq local(1990, 10, 1, 02, 30, 24) }
      it { expect(convert_timezone_if_date("1990-01-01T02:30:24Z-03:00")).to eq "1990-01-01T02:30:24Z-03:00" }
    end
    context 'when there is no local timezone' do
      before { Time.zone = nil }
      it { expect(convert_timezone_if_date("1990-10-01")).to eq "1990-10-01" }
      it { expect(convert_timezone_if_date("1990-10-01T02:30:24")).to eq "1990-10-01T02:30:24" }
      it { expect(convert_timezone_if_date("1990-01-01T02:30:24-03:00")).to eq "1990-01-01T02:30:24-03:00" }
    end
  end

  def local(*args)
    Time.zone.local(*args).iso8601
  end
end
{'fraction_non_alphanumeric': 0.14828718911309244, 'fraction_numerical': 0.12763960581886438, 'mean_word_length': 4.370277078085643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5991950', 'n_tokens_mistral': 991, 'n_tokens_neox': 804, 'n_words': 159}