123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- describe('Date', function () {
-
- describe('now', function () {
- it('should be the current time', function () {
- expect(Date.now() === new Date().getTime()).toBe(true);
- });
- });
- describe("parse", function () {
-
- it('should support extended years', function () {
- expect(Date.parse('0001-01-01T00:00:00Z')).toBe(-62135596800000);
- expect(Date.parse('+275760-09-13T00:00:00.000Z')).toBe(8.64e15);
- expect(Date.parse('+033658-09-27T01:46:40.000Z')).toBe(1e15);
- expect(Date.parse('-000001-01-01T00:00:00Z')).toBe(-62198755200000);
- expect(Date.parse('+002009-12-15T00:00:00Z')).toBe(1260835200000);
- });
- it('should work', function () {
-
- expect(Date.parse("2012-11-31T23:59:59.000Z")).toBeFalsy();
- expect(Date.parse("2012-12-31T23:59:59.000Z")).toBe(1356998399000);
- expect(Date.parse("2012-12-31T23:59:60.000Z")).toBeFalsy();
- expect(Date.parse("2012-04-04T05:02:02.170Z")).toBe(1333515722170);
- expect(Date.parse("2012-04-04T24:00:00.000Z")).toBe(1333584000000);
- expect(Date.parse("2012-04-04T24:00:00.500Z")).toBeFalsy();
- expect(Date.parse("2012-12-31T10:08:60.000Z")).toBeFalsy();
- expect(Date.parse("2012-13-01T12:00:00.000Z")).toBeFalsy();
- expect(Date.parse("2012-12-32T12:00:00.000Z")).toBeFalsy();
- expect(Date.parse("2012-12-31T25:00:00.000Z")).toBeFalsy();
- expect(Date.parse("2012-12-31T24:01:00.000Z")).toBeFalsy();
- expect(Date.parse("2012-12-31T12:60:00.000Z")).toBeFalsy();
- expect(Date.parse("2012-12-31T12:00:60.000Z")).toBeFalsy();
- expect(Date.parse("2012-00-31T23:59:59.000Z")).toBeFalsy();
- expect(Date.parse("2012-12-00T23:59:59.000Z")).toBeFalsy();
- expect(Date.parse("2012-02-29T12:00:00.000Z")).toBe(1330516800000);
- expect(Date.parse("2011-02-29T12:00:00.000Z")).toBeFalsy();
- expect(Date.parse("2011-03-01T12:00:00.000Z")).toBe(1298980800000);
-
- expect(Date.parse("0000-01-01T00:00:00.000Z")).toBe(-621672192e5);
- expect(Date.parse("+275760-09-13T00:00:00.000Z")).toBe(8.64e15);
- expect(Date.parse("-271821-04-20T00:00:00.000Z")).toBe(-8.64e15);
- expect(Date.parse("+275760-09-13T00:00:00.001Z")).toBeFalsy();
- expect(Date.parse("-271821-04-19T23:59:59.999Z")).toBeFalsy();
-
- expect(Date.parse("2034-03-01T00:00:00.000Z") -
- Date.parse("2034-02-27T23:59:59.999Z")).toBe(86400001);
-
- expect(Date.parse("2012-01-29T12:00:00.000+01:00")).toBe(132783480e4);
- expect(Date.parse("2012-01-29T12:00:00.000-00:00")).toBe(132783840e4);
- expect(Date.parse("2012-01-29T12:00:00.000+00:00")).toBe(132783840e4);
- expect(Date.parse("2012-01-29T12:00:00.000+23:59")).toBe(132775206e4);
- expect(Date.parse("2012-01-29T12:00:00.000-23:59")).toBe(132792474e4);
- expect(Date.parse("2012-01-29T12:00:00.000+24:00")).toBeFalsy();
- expect(Date.parse("2012-01-29T12:00:00.000+24:01")).toBeFalsy();
- expect(Date.parse("2012-01-29T12:00:00.000+24:59")).toBeFalsy();
- expect(Date.parse("2012-01-29T12:00:00.000+25:00")).toBeFalsy();
- expect(Date.parse("2012-01-29T12:00:00.000+00:60")).toBeFalsy();
- expect(Date.parse("-271821-04-20T00:00:00.000+00:01")).toBeFalsy();
- expect(Date.parse("-271821-04-20T00:01:00.000+00:01")).toBe(-8.64e15);
-
-
- var tzOffset = Number(new Date(1970, 0));
-
- expect(Date.parse('1970-01-01T00:00:00')).toBe(tzOffset);
- });
- });
- describe("toISOString", function () {
-
-
- it('should support extended years', function () {
- expect(new Date(-62198755200000).toISOString().indexOf('-000001-01-01')).toBe(0);
- expect(new Date(8.64e15).toISOString().indexOf('+275760-09-13')).toBe(0);
- });
- it('should return correct dates', function () {
- expect(new Date(-1).toISOString()).toBe('1969-12-31T23:59:59.999Z');
- expect(new Date(-3509827334573292).toISOString()).toBe('-109252-01-01T10:37:06.708Z');
- });
- });
- describe("toJSON", function () {
-
- it('should call toISOString', function () {
- var date = new Date(0);
- date.toISOString = function () {
- return 1;
- };
- expect(date.toJSON()).toBe(1);
- });
- it('should return null for not finite dates', function () {
- var date = new Date(NaN),
- json;
- try {
- json = date.toJSON();
- } catch (e) {}
- expect(json).toBe(null);
- });
- it('should return the isoString when stringified', function () {
- var date = new Date();
- expect(JSON.stringify(date.toISOString())).toBe(JSON.stringify(date));
- })
- });
- });
|