~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/date/test_date_parse.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
656
656
      Date.parse('')
657
657
    end
658
658
    assert_raise(ArgumentError) do
 
659
      DateTime.parse('')
 
660
    end
 
661
    assert_raise(ArgumentError) do
659
662
      Date.parse('2001-02-29')
660
663
    end
661
664
    assert_raise(ArgumentError) do
667
670
  end
668
671
 
669
672
  def test__iso8601
670
 
    h = Date._iso8601('01-02-03')
671
 
    assert_equal([2001, 2, 3, nil, nil, nil, nil],
672
 
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
673
 
    h = Date._iso8601('2001-02-03')
674
 
    assert_equal([2001, 2, 3, nil, nil, nil, nil],
675
 
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
676
 
    h = Date._iso8601('--02-03')
677
 
    assert_equal([nil, 2, 3, nil, nil, nil, nil],
 
673
    h = Date._iso8601('01-02-03T04:05:06Z')
 
674
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
675
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
 
676
    h = Date._iso8601('2001-02-03T04:05:06Z')
 
677
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
678
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
 
679
    h = Date._iso8601('--02-03T04:05:06Z')
 
680
    assert_equal([nil, 2, 3, 4, 5, 6, 0],
 
681
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
 
682
    h = Date._iso8601('---03T04:05:06Z')
 
683
    assert_equal([nil, nil, 3, 4, 5, 6, 0],
678
684
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
679
685
 
680
686
    h = Date._iso8601('2001-02-03T04:05')
693
699
    assert_equal([2001, 2, 3, 4, 5, 6, 3600],
694
700
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
695
701
 
696
 
    h = Date._iso8601('010203')
697
 
    assert_equal([2001, 2, 3, nil, nil, nil, nil],
698
 
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
699
 
    h = Date._iso8601('20010203')
700
 
    assert_equal([2001, 2, 3, nil, nil, nil, nil],
701
 
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
702
 
    h = Date._iso8601('--0203')
703
 
    assert_equal([nil, 2, 3, nil, nil, nil, nil],
 
702
    h = Date._iso8601('010203T040506Z')
 
703
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
704
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
 
705
    h = Date._iso8601('20010203T040506Z')
 
706
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
707
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
 
708
    h = Date._iso8601('--0203T040506Z')
 
709
    assert_equal([nil, 2, 3, 4, 5, 6, 0],
 
710
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
 
711
    h = Date._iso8601('---03T040506Z')
 
712
    assert_equal([nil, nil, 3, 4, 5, 6, 0],
704
713
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
705
714
 
706
715
    h = Date._iso8601('010203T0405')
738
747
    assert_equal([2001, 2, 3, 4, 5, 6, 3600],
739
748
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
740
749
 
741
 
    h = Date._iso8601('01-023')
742
 
    assert_equal([2001, 23, nil, nil, nil, nil],
743
 
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
744
 
    h = Date._iso8601('2001-023')
745
 
    assert_equal([2001, 23, nil, nil, nil, nil],
746
 
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
747
 
    h = Date._iso8601('-023')
748
 
    assert_equal([nil, 23, nil, nil, nil, nil],
749
 
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
 
750
    h = Date._iso8601('01-023T04:05:06Z')
 
751
    assert_equal([2001, 23, 4, 5, 6, 0],
 
752
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
 
753
    h = Date._iso8601('2001-023T04:05:06Z')
 
754
    assert_equal([2001, 23, 4, 5, 6, 0],
 
755
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
 
756
    h = Date._iso8601('-023T04:05:06Z')
 
757
    assert_equal([nil, 23, 4, 5, 6, 0],
 
758
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
 
759
 
 
760
    h = Date._iso8601('01023T040506Z')
 
761
    assert_equal([2001, 23, 4, 5, 6, 0],
 
762
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
 
763
    h = Date._iso8601('2001023T040506Z')
 
764
    assert_equal([2001, 23, 4, 5, 6, 0],
 
765
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
 
766
    h = Date._iso8601('-023T040506Z')
 
767
    assert_equal([nil, 23, 4, 5, 6, 0],
 
768
                 h.values_at(:year, :yday, :hour, :min, :sec, :offset))
 
769
 
 
770
    h = Date._iso8601('01-w02-3T04:05:06Z')
 
771
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
772
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
 
773
    h = Date._iso8601('2001-w02-3T04:05:06Z')
 
774
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
775
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
 
776
    h = Date._iso8601('-w02-3T04:05:06Z')
 
777
    assert_equal([nil, 2, 3, 4, 5, 6, 0],
 
778
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
 
779
    h = Date._iso8601('-w-3T04:05:06Z')
 
780
    assert_equal([nil, nil, 3, 4, 5, 6, 0],
 
781
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
 
782
 
 
783
    h = Date._iso8601('01w023T040506Z')
 
784
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
785
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
 
786
    h = Date._iso8601('2001w023T040506Z')
 
787
    assert_equal([2001, 2, 3, 4, 5, 6, 0],
 
788
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
 
789
    h = Date._iso8601('-w023T040506Z')
 
790
    assert_equal([nil, 2, 3, 4, 5, 6, 0],
 
791
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
 
792
    h = Date._iso8601('-w-3T040506Z')
 
793
    assert_equal([nil, nil, 3, 4, 5, 6, 0],
 
794
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
750
795
 
751
796
    h = Date._iso8601('04:05')
752
797
    assert_equal([nil, nil, nil, 4, 5, nil, nil],
771
816
    assert_equal([nil, nil, nil, 4, 5, 6, 3600],
772
817
                 h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
773
818
 
774
 
    h = Date._iso8601('01-w02-3')
775
 
    assert_equal([2001, 2, 3, nil, nil, nil, nil],
776
 
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
777
 
    h = Date._iso8601('2001-w02-3')
778
 
    assert_equal([2001, 2, 3, nil, nil, nil, nil],
779
 
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
780
 
    h = Date._iso8601('2001w023')
781
 
    assert_equal([2001, 2, 3, nil, nil, nil, nil],
782
 
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
783
 
    h = Date._iso8601('-w02-3')
784
 
    assert_equal([nil, 2, 3, nil, nil, nil, nil],
785
 
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
786
 
    h = Date._iso8601('-w-3')
787
 
    assert_equal([nil, nil, 3, nil, nil, nil, nil],
788
 
                 h.values_at(:cwyear, :cweek, :cwday, :hour, :min, :sec, :offset))
789
819
  end
790
820
 
791
821
  def test__rfc3339
953
983
  def test_iso8601
954
984
    assert_instance_of(Date, Date.iso8601)
955
985
    assert_instance_of(DateTime, DateTime.iso8601)
 
986
 
 
987
    d = Date.iso8601('2001-02-03', Date::ITALY + 10)
 
988
    assert_equal(Date.new(2001,2,3), d)
 
989
    assert_equal(Date::ITALY + 10, d.start)
 
990
 
 
991
    d = DateTime.iso8601('2001-02-03T04:05:06+07:00', Date::ITALY + 10)
 
992
    assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
 
993
    assert_equal(Date::ITALY + 10, d.start)
956
994
  end
957
995
 
958
996
  def test_rfc3339
959
997
    assert_instance_of(Date, Date.rfc3339)
960
998
    assert_instance_of(DateTime, DateTime.rfc3339)
 
999
 
 
1000
    d = Date.rfc3339('2001-02-03T04:05:06+07:00', Date::ITALY + 10)
 
1001
    assert_equal(Date.new(2001,2,3), d)
 
1002
    assert_equal(Date::ITALY + 10, d.start)
 
1003
 
 
1004
    d = DateTime.rfc3339('2001-02-03T04:05:06+07:00', Date::ITALY + 10)
 
1005
    assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
 
1006
    assert_equal(Date::ITALY + 10, d.start)
961
1007
  end
962
1008
 
963
1009
  def test_xmlschema
964
1010
    assert_instance_of(Date, Date.xmlschema)
965
1011
    assert_instance_of(DateTime, DateTime.xmlschema)
 
1012
 
 
1013
    d = Date.xmlschema('2001-02-03', Date::ITALY + 10)
 
1014
    assert_equal(Date.new(2001,2,3), d)
 
1015
    assert_equal(Date::ITALY + 10, d.start)
 
1016
 
 
1017
    d = DateTime.xmlschema('2001-02-03T04:05:06+07:00', Date::ITALY + 10)
 
1018
    assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
 
1019
    assert_equal(Date::ITALY + 10, d.start)
966
1020
  end
967
1021
 
968
1022
  def test_rfc2822
970
1024
    assert_instance_of(DateTime, DateTime.rfc2822)
971
1025
    assert_instance_of(Date, Date.rfc822)
972
1026
    assert_instance_of(DateTime, DateTime.rfc822)
 
1027
 
 
1028
    d = Date.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700', Date::ITALY + 10)
 
1029
    assert_equal(Date.new(2001,2,3), d)
 
1030
    assert_equal(Date::ITALY + 10, d.start)
 
1031
 
 
1032
    d = DateTime.rfc2822('Sat, 3 Feb 2001 04:05:06 +0700', Date::ITALY + 10)
 
1033
    assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
 
1034
    assert_equal(Date::ITALY + 10, d.start)
973
1035
  end
974
1036
 
975
1037
  def test_httpdate
976
1038
    assert_instance_of(Date, Date.httpdate)
977
1039
    assert_instance_of(DateTime, DateTime.httpdate)
 
1040
 
 
1041
    d = Date.httpdate('Sat, 03 Feb 2001 04:05:06 GMT', Date::ITALY + 10)
 
1042
    assert_equal(Date.new(2001,2,3), d)
 
1043
    assert_equal(Date::ITALY + 10, d.start)
 
1044
 
 
1045
    d = DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT', Date::ITALY + 10)
 
1046
    assert_equal(DateTime.new(2001,2,3,4,5,6,'+00:00'), d)
 
1047
    assert_equal(Date::ITALY + 10, d.start)
978
1048
  end
979
1049
 
980
1050
  def test_jisx0301
981
1051
    assert_instance_of(Date, Date.jisx0301)
982
1052
    assert_instance_of(DateTime, DateTime.jisx0301)
 
1053
 
 
1054
    d = Date.jisx0301('H13.02.03', Date::ITALY + 10)
 
1055
    assert_equal(Date.new(2001,2,3), d)
 
1056
    assert_equal(Date::ITALY + 10, d.start)
 
1057
 
 
1058
    d = DateTime.jisx0301('H13.02.03T04:05:06+07:00', Date::ITALY + 10)
 
1059
    assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
 
1060
    assert_equal(Date::ITALY + 10, d.start)
983
1061
  end
984
1062
 
985
1063
end