<commit_before>require "spec_helper"

describe Mongoid::Extensions::Date::Conversions do

  before do
    @time = Date.today.to_time
  end

  describe "#set" do

    context "when string provided" do

      context "when string is a non utc time" do

        it "returns a utc time from the string" do
          Date.set(@time.to_s).should == @time.utc
        end

      end

      context "when string is a date" do

        it "returns a time from the string" do
          date = RUBY_VERSION.start_with?("1.9") ? "15/01/2007" : "01/15/2007"
          Date.set(date).should == Date.new(2007, 1, 15).at_midnight.utc
        end

      end

      context "when string is empty" do

        it "returns nil" do
          Date.set("").should == nil
        end

      end

    end

    context "when time provided" do

      it "returns the time" do
        Date.set(@time).should == @time.utc
      end

    end

    context "when a date provided" do

      it "returns a time from the date" do
        Date.set(@time.to_date).should == @time
      end

    end

  end

  describe "#get" do

    context "when value is nil" do

      it "returns nil" do
        Date.get(nil).should be_nil
      end

    end

    context "when value is not nil" do

      context "when time is UTC" do

        before do
          @utc = Date.new(1974, 12, 1).to_time.utc
        end

        context "when time zone is not utc" do
<commit_msg>Fix date conversion specs to expect utc times at midnight.<commit_after>require "spec_helper"

describe Mongoid::Extensions::Date::Conversions do

  before do
    @time = Date.today.to_time
  end

  describe "#set" do

    context "when string provided" do

      context "when string is a non utc time" do

        it "returns a utc time from the string" do
          time_in_millis = Time.at((@time.to_f * 1000).round / 1000)
          Date.set(@time.to_s).should == time_in_millis.utc.at_midnight
        end

      end

      context "when string is a date" do

        it "returns a time from the string" do
          date = RUBY_VERSION.start_with?("1.9") ? "15/01/2007" : "01/15/2007"
          Date.set(date).should == Date.civil(2007, 1, 15).to_time.utc.at_midnight
        end

      end

      context "when string is empty" do

        it "returns nil" do
          Date.set("").should == nil
        end

      end

    end

    context "when time provided" do

      it "returns the date for the time" do
        Date.set(@time).should == @time.utc.at_midnight
      end

    end

    context "when a date provided" do

      it "returns a time from the date" do
        Date.set(@time.to_date).should == @time.utc.at_midnight
      end

    end

  end

  describe "#get" do

    context "when value is nil" do

      it "returns nil" do
        Date.get(nil).should be_nil
      end

    end

    context "when value is not nil" do

      context "when time is UTC" do

        before do
          @utc = Date.new(1974, 12, 1).to_time.utc
        end

        context "when time zone is not utc" do

{'fraction_non_alphanumeric': 0.09270216962524655, 'fraction_numerical': 0.023668639053254437, 'mean_word_length': 1.920345489443378, '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': '931517', 'n_tokens_mistral': 1052, 'n_tokens_neox': 935, 'n_words': 332}