<commit_before>require 'spec_helper'

describe Localized::Parser::TimeParser do
  context 'en locale' do
    before { I18n.locale = :en }

    describe '#parse' do
      it { subject.parse('Fri, 3 Oct 2014 12:01:00 -0200').should eq time_object(year: 2014, month: 10, day: 3, hour: 12, min: 1, sec: 0) }

      it { subject.parse('Fri, 22 Jan 1988 20:54:00 -0200').should eq time_object(year: 1988, month: 1, day: 22, hour: 20, min: 54, sec: 0) }

      it { subject.parse('Fri, 22 Jan 1988 20:54:00').should eq time_object(year: 1988, month: 1, day: 22, hour: 20, min: 54, sec: 0) }

      it { subject.parse('Fri, 22 Jan 1988 20:54').should eq time_object(year: 1988, month: 1, day: 22, hour: 20, min: 54) }

      it { subject.parse('20:54:00').should eq time_object(hour: 20, min: 54, sec: 0) }

      it { subject.parse('20:54').should eq time_object(hour: 20, min: 54) }
    end

    describe '#localize' do
      it { subject.localize(Time.new(2010, 10, 25, 1, 33)).should eq 'Mon, 25 Oct 2010 01:33:00 -0200' }
    end
  end

  context 'pt-BR locale' do
    before { I18n.locale = :'pt-BR' }

    describe '#parse' do
      it { subject.parse('7/11/2014 9:35').should eq time_object(year: 2014, month: 11, day: 7, hour: 9, min: 35) }

      it { subject.parse('31/02/2014 8:00').should eq time_object(year: 2014, month: 2, day: 31, hour: 8, min: 0) }

      it { subject.parse('15-7-1997 23:00').should eq time_object(year: 1997, month: 7, day: 15, hour: 23, min: 0) }

      it { subject.parse('23:00:10').should eq time_object(hour: 23, min: 0, sec: 10) }

      it { subject.parse('23:00').should eq time_object(hour: 23, min: 00) }
    end

    describe '#localize' do
      it { subject.localize(Time.new(2014, 2, 14, 17, 55)).should eq '14/02/2014 17:55' }
    end
  end
end

def time_object(year: Date.today.year, month: Date.today.mon, day: Date.today.mday, hour: Time.now.hour, min: Time.now.min, sec: Time.now.sec)
  Time.utc year, month, day, hour, min, sec
end
<commit_msg>Fixed test of module TimeParser.<commit_after>require 'spec_helper'

describe Localized::Parser::TimeParser do
  context 'en locale' do
    before { I18n.locale = :en }

    describe '#parse' do
      it { subject.parse('Fri, 3 Oct 2014 12:01:00 -0200').should eq time_object(year: 2014, month: 10, day: 3, hour: 12, min: 1, sec: 0) }

      it { subject.parse('Fri, 22 Jan 1988 20:54:00 -0200').should eq time_object(year: 1988, month: 1, day: 22, hour: 20, min: 54, sec: 0) }

      it { subject.parse('Fri, 22 Jan 1988 20:54:00').should eq time_object(year: 1988, month: 1, day: 22, hour: 20, min: 54, sec: 0) }

      it { subject.parse('Fri, 22 Jan 1988 20:54').should eq time_object(year: 1988, month: 1, day: 22, hour: 20, min: 54) }

      it { subject.parse('20:54:00').should eq time_object(hour: 20, min: 54, sec: 0) }

      it { subject.parse('20:54').should eq time_object(hour: 20, min: 54) }
    end

    describe '#localize' do
      it { subject.localize(Time.utc(2010, 10, 25, 1, 33)).should eq 'Mon, 25 Oct 2010 01:33:00 +0000' }
    end
  end

  context 'pt-BR locale' do
    before { I18n.locale = :'pt-BR' }

    describe '#parse' do
      it { subject.parse('7/11/2014 9:35').should eq time_object(year: 2014, month: 11, day: 7, hour: 9, min: 35) }

      it { subject.parse('31/02/2014 8:00').should eq time_object(year: 2014, month: 2, day: 31, hour: 8, min: 0) }

      it { subject.parse('15-7-1997 23:00').should eq time_object(year: 1997, month: 7, day: 15, hour: 23, min: 0) }

      it { subject.parse('23:00:10').should eq time_object(hour: 23, min: 0, sec: 10) }

      it { subject.parse('23:00').should eq time_object(hour: 23, min: 00) }
    end

    describe '#localize' do
      it { subject.localize(Time.new(2014, 2, 14, 17, 55)).should eq '14/02/2014 17:55' }
    end
  end
end

def time_object(year: Date.today.year, month: Date.today.mon, day: Date.today.mday, hour: Time.now.hour, min: Time.now.min, sec: Time.now.sec)
  Time.utc year, month, day, hour, min, sec
end

{'fraction_non_alphanumeric': 0.16504369538077404, 'fraction_numerical': 0.1258426966292135, 'mean_word_length': 3.3029001074113857, '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': '7570993', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1456, 'n_words': 466}