parse_time_spec.coffee 2.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. describe '#parseTime', ->
  2. it 'should parse years', ->
  3. Morris.parseDate('2012').should.equal(new Date(2012, 0, 1).getTime())
  4. it 'should parse quarters', ->
  5. Morris.parseDate('2012 Q1').should.equal(new Date(2012, 2, 1).getTime())
  6. it 'should parse months', ->
  7. Morris.parseDate('2012-09').should.equal(new Date(2012, 8, 1).getTime())
  8. Morris.parseDate('2012-10').should.equal(new Date(2012, 9, 1).getTime())
  9. it 'should parse dates', ->
  10. Morris.parseDate('2012-09-15').should.equal(new Date(2012, 8, 15).getTime())
  11. Morris.parseDate('2012-10-15').should.equal(new Date(2012, 9, 15).getTime())
  12. it 'should parse times', ->
  13. Morris.parseDate("2012-10-15 12:34").should.equal(new Date(2012, 9, 15, 12, 34).getTime())
  14. Morris.parseDate("2012-10-15T12:34").should.equal(new Date(2012, 9, 15, 12, 34).getTime())
  15. Morris.parseDate("2012-10-15 12:34:55").should.equal(new Date(2012, 9, 15, 12, 34, 55).getTime())
  16. Morris.parseDate("2012-10-15T12:34:55").should.equal(new Date(2012, 9, 15, 12, 34, 55).getTime())
  17. it 'should parse times with timezones', ->
  18. Morris.parseDate("2012-10-15T12:34+0100").should.equal(Date.UTC(2012, 9, 15, 11, 34))
  19. Morris.parseDate("2012-10-15T12:34+02:00").should.equal(Date.UTC(2012, 9, 15, 10, 34))
  20. Morris.parseDate("2012-10-15T12:34-0100").should.equal(Date.UTC(2012, 9, 15, 13, 34))
  21. Morris.parseDate("2012-10-15T12:34-02:00").should.equal(Date.UTC(2012, 9, 15, 14, 34))
  22. Morris.parseDate("2012-10-15T12:34:55Z").should.equal(Date.UTC(2012, 9, 15, 12, 34, 55))
  23. Morris.parseDate("2012-10-15T12:34:55+0600").should.equal(Date.UTC(2012, 9, 15, 6, 34, 55))
  24. Morris.parseDate("2012-10-15T12:34:55+04:00").should.equal(Date.UTC(2012, 9, 15, 8, 34, 55))
  25. Morris.parseDate("2012-10-15T12:34:55-0600").should.equal(Date.UTC(2012, 9, 15, 18, 34, 55))
  26. it 'should pass-through timestamps', ->
  27. Morris.parseDate(new Date(2012, 9, 15, 12, 34, 55, 123).getTime())
  28. .should.equal(new Date(2012, 9, 15, 12, 34, 55, 123).getTime())