Sha256: 3dc76b2267e0eac1df9702f161fa1e1296e5e3bceaab4a00d012871c90d7d5fe

Contents?: true

Size: 1.96 KB

Versions: 15

Compression:

Stored size: 1.96 KB

Contents

describe "Base Methods" do

  it "parses a relative natural language string, returning a date" do
    today = Time.now
    t = SugarCube::DateParser.parse_date("tomorrow at 7:30 PM")
    t.should.is_a Time
    t.hour.should == 19
    t.min.should == 30
    t.sec.should == 0
    (t.day - today.day).should == 1
  end

  it "parses a specific natural language string, returning a date" do
    t = SugarCube::DateParser.parse_date("6/18/13 at 7:30 AM")
    t.month.should == 6
    t.day.should == 18
    t.year.should == 2013
    t.hour.should == 7
    t.min.should == 30
  end

  it "returns nil on failure" do
    t = SugarCube::DateParser.parse_date("NOT A DATE")
    t.should == nil
  end

  describe "parses iso8601 dates" do

    it "parses '2013-08-22T21:34:48.874Z'" do
      t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874Z")
      t.month.should == 8
      t.day.should == 22
      t.year.should == 2013
      t.min.should == 34
      t.sec.should == 48
      t.usec.should == 874000
    end

    it "parses '2013-08-22T21:34:48.874'" do
      t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48.874")
      t.month.should == 8
      t.day.should == 22
      t.year.should == 2013
      t.min.should == 34
      t.sec.should == 48
      t.usec.should == 874000
    end

    it "parses '2013-08-22T21:34:48Z'" do
      t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48Z")
      t.month.should == 8
      t.day.should == 22
      t.year.should == 2013
      t.min.should == 34
      t.sec.floor.should == 48
    end

    it "parses '2013-08-22T21:34:48'" do
      t = SugarCube::DateParser.parse_date("2013-08-22T21:34:48")
      t.month.should == 8
      t.day.should == 22
      t.year.should == 2013
      t.min.should == 34
      t.sec.floor.should == 48
    end

  end

end

describe "String Extensions" do
  it "parses a date the same as the base method" do
    "tomorrow at 7:30 PM".to_date.should == SugarCube::DateParser.parse_date("tomorrow at 7:30 PM")
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sugarcube-1.4.1 spec/date_parser_spec.rb
sugarcube-1.4.0 spec/date_parser_spec.rb
sugarcube-1.3.11 spec/date_parser_spec.rb
sugarcube-1.3.10 spec/date_parser_spec.rb
sugarcube-1.3.9 spec/date_parser_spec.rb
sugarcube-1.3.8 spec/date_parser_spec.rb
sugarcube-1.3.7 spec/date_parser_spec.rb
sugarcube-1.3.6 spec/date_parser_spec.rb
sugarcube-1.3.5 spec/date_parser_spec.rb
sugarcube-1.3.4 spec/date_parser_spec.rb
sugarcube-1.3.3 spec/date_parser_spec.rb
sugarcube-1.3.2 spec/date_parser_spec.rb
sugarcube-1.3.1 spec/date_parser_spec.rb
sugarcube-1.3.0 spec/date_parser_spec.rb
sugarcube-1.1.0 spec/date_parser_spec.rb