yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
import { Iso8601 } from "../../Source/Cesium.js";
import { JulianDate } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { TimeConstants } from "../../Source/Cesium.js";
import { TimeStandard } from "../../Source/Cesium.js";
 
describe("Core/JulianDate", function () {
  // All exact Julian Dates found using NASA's Time Conversion Tool: http://ssd.jpl.nasa.gov/tc.cgi
  it("Construct a default date", function () {
    var defaultDate = new JulianDate();
    expect(defaultDate.dayNumber).toEqual(0);
    expect(defaultDate.secondsOfDay).toEqual(10);
  });
 
  it("Construct a date with fractional day", function () {
    var julianDate = new JulianDate(2448257.75, 0, TimeStandard.UTC);
    var expected = new JulianDate(2448257, 64826, TimeStandard.TAI);
    expect(julianDate).toEqual(expected);
  });
 
  it("Construct a date at the current time", function () {
    // Default constructing a date uses 'now'.  Unfortunately,
    // there's no way to know exactly what that time will be, so we
    // give ourselves a 5 second epsilon as a hack to avoid possible
    // race conditions.  In reality, it might be better to just omit
    // a check in this test, since if this breaks, tons of other stuff
    // will as well.
    var defaultDate = JulianDate.now();
    var dateNow = JulianDate.fromDate(new Date());
    expect(defaultDate.equalsEpsilon(dateNow, 5)).toEqual(true);
  });
 
  it("Construct a date from basic TAI components", function () {
    var dayNumber = 12;
    var seconds = 12.5;
    var timeStandard = TimeStandard.TAI;
    var julianDate = new JulianDate(dayNumber, seconds, timeStandard);
    expect(julianDate.dayNumber).toEqual(dayNumber);
    expect(julianDate.secondsOfDay).toEqual(seconds);
  });
 
  it("clone works without result parameter", function () {
    var julianDate = JulianDate.now();
    var returnedResult = julianDate.clone();
    expect(returnedResult).toEqual(julianDate);
    expect(returnedResult).not.toBe(julianDate);
  });
 
  it("clone works with result parameter", function () {
    var julianDate = new JulianDate(1, 2);
    var result = JulianDate.now();
    var returnedResult = julianDate.clone(result);
    expect(returnedResult).toBe(result);
    expect(returnedResult).not.toBe(julianDate);
    expect(returnedResult).toEqual(julianDate);
  });
 
  it("Construct a date from UTC components just before a leap second", function () {
    var expected = new JulianDate(2443874, 43216, TimeStandard.TAI);
    var julianDate = new JulianDate(2443874, 43199.0, TimeStandard.UTC);
    expect(julianDate.dayNumber).toEqual(expected.dayNumber);
    expect(julianDate.secondsOfDay).toEqual(expected.secondsOfDay);
  });
 
  it("Construct a date from UTC components equivalent to a LeapSecond table entry", function () {
    var expected = new JulianDate(2443874, 43218, TimeStandard.TAI);
    var julianDate = new JulianDate(2443874, 43200.0, TimeStandard.UTC);
    expect(julianDate.dayNumber).toEqual(expected.dayNumber);
    expect(julianDate.secondsOfDay).toEqual(expected.secondsOfDay);
  });
 
  it("Construct a date from UTC components just after a leap second", function () {
    var expected = new JulianDate(2443874, 43219, TimeStandard.TAI);
    var julianDate = new JulianDate(2443874, 43201.0, TimeStandard.UTC);
    expect(julianDate.dayNumber).toEqual(expected.dayNumber);
    expect(julianDate.secondsOfDay).toEqual(expected.secondsOfDay);
  });
 
  it("Construct a date from basic components with more seconds than a day", function () {
    var dayNumber = 12;
    var seconds = 86401;
    var timeStandard = TimeStandard.TAI;
    var julianDate = new JulianDate(dayNumber, seconds, timeStandard);
    expect(julianDate.dayNumber).toEqual(13);
    expect(julianDate.secondsOfDay).toEqual(1);
  });
 
  it("Construct a date from basic components with negative seconds in a day", function () {
    var dayNumber = 12;
    var seconds = -1;
    var timeStandard = TimeStandard.TAI;
    var julianDate = new JulianDate(dayNumber, seconds, timeStandard);
    expect(julianDate.dayNumber).toEqual(11);
    expect(julianDate.secondsOfDay).toEqual(86399);
  });
 
  it("Construct a date from basic components with partial day and seconds in a day", function () {
    var dayNumber = 12.5;
    var seconds = -1;
    var timeStandard = TimeStandard.TAI;
    var julianDate = new JulianDate(dayNumber, seconds, timeStandard);
    expect(julianDate.dayNumber).toEqual(12);
    expect(julianDate.secondsOfDay).toEqual(43199);
  });
 
  it("Construct a date with default time standard", function () {
    var dayNumber = 12;
    var seconds = 12.5;
    var julianDateDefault = new JulianDate(dayNumber, seconds);
    var julianDateUtc = new JulianDate(dayNumber, seconds, TimeStandard.UTC);
    expect(julianDateDefault).toEqual(julianDateUtc);
  });
 
  it("Construct a date from a JavaScript Date (1)", function () {
    var date = new Date("January 1, 1991 06:00:00 UTC");
    var julianDate = JulianDate.fromDate(date);
    expect(julianDate.dayNumber).toEqual(2448257);
    expect(julianDate.secondsOfDay).toEqual(64826);
  });
 
  it("Construct a date from a JavaScript Date (2)", function () {
    var date = new Date("July 4, 2011 12:00:00 UTC");
    var julianDate = JulianDate.fromDate(date);
    expect(julianDate.dayNumber).toEqual(2455747);
    expect(julianDate.secondsOfDay).toEqual(34);
  });
 
  it("Construct a date from a JavaScript Date (3)", function () {
    var date = new Date("December 31, 2021 18:00:00 UTC");
    var julianDate = JulianDate.fromDate(date);
    expect(julianDate.dayNumber).toEqual(2459580);
    expect(julianDate.secondsOfDay).toEqual(21637);
  });
 
  it("Construct a date from a JavaScript Date (4)", function () {
    var jsDate = new Date("September 1, 2011 12:00:00 UTC");
    var julianDate = JulianDate.fromDate(jsDate);
    expect(julianDate.dayNumber).toEqual(2455806);
    expect(julianDate.secondsOfDay).toEqual(34);
  });
 
  it("Construct a date from a JavaScript Date (5)", function () {
    var jsDate = new Date("11/17/2039 12:00:00 AM UTC");
    var julianDate = JulianDate.fromDate(jsDate);
    expect(julianDate.dayNumber).toEqual(2466109);
    expect(julianDate.secondsOfDay).toEqual(43237);
  });
 
  it("Fail to construct from an undefined JavaScript Date", function () {
    expect(function () {
      return JulianDate.fromDate(undefined);
    }).toThrowDeveloperError();
  });
 
  it("Fail to construct from an invalid JavaScript Date", function () {
    expect(function () {
      return JulianDate.fromDate(new Date(Date.parse("garbage")));
    }).toThrowDeveloperError();
  });
 
  it("Construct from ISO8601 calendar date, basic format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2009, 7, 1)));
    var computedDate = JulianDate.fromIso8601("20090801");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 calendar date, extended format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2009, 7, 1)));
    var computedDate = JulianDate.fromIso8601("2009-08-01");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 calendar date on Feb 29th, basic format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2000, 1, 29)));
    var computedDate = JulianDate.fromIso8601("20000229");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 calendar date on Feb 29th, extended format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2000, 1, 29)));
    var computedDate = JulianDate.fromIso8601("2000-02-29");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 ordinal date, basic format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(1985, 3, 12)));
    var computedDate = JulianDate.fromIso8601("1985102");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 ordinal date, extended format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(1985, 3, 12)));
    var computedDate = JulianDate.fromIso8601("1985-102");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct an ISO8601 ordinal date on a leap year", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2000, 11, 31)));
    var computedDate = JulianDate.fromIso8601("2000-366");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 week date, basic format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(1985, 3, 12)));
    var computedDate = JulianDate.fromIso8601("1985W155");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 week date, extended format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2008, 8, 27)));
    var computedDate = JulianDate.fromIso8601("2008-W39-6");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 calendar week date, basic format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(1985, 3, 7)));
    var computedDate = JulianDate.fromIso8601("1985W15");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 calendar week date, extended format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2008, 8, 21)));
    var computedDate = JulianDate.fromIso8601("2008-W39");
    expect(computedDate).toEqual(expectedDate);
  });
 
  //Note, there is no 'extended format' for calendar month because eliminating the
  //would confuse is with old YYMMDD dates
  it("Construct from an ISO8601 calendar month, basic format", function () {
    var expectedDate = JulianDate.fromDate(new Date(Date.UTC(1985, 3, 1)));
    var computedDate = JulianDate.fromIso8601("1985-04");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time, basic format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 25))
    );
    var computedDate = JulianDate.fromIso8601("20090801T123025Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time, extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 25))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T12:30:25Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time fractional seconds, basic format", function () {
    //Date is only accurate to milliseconds, while JulianDate, much more so.  The below date gets
    //rounded to 513, so we need to construct a JulianDate directly.
    //var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2009, 7, 1, 12, 30, 25, 5125423)));
    var expectedDate = new JulianDate(2455045, 1825.5125423, TimeStandard.UTC);
    var computedDate = JulianDate.fromIso8601("20090801T123025.5125423Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time fractional seconds, extended format", function () {
    //Date is only accurate to milliseconds, while JulianDate, much more so.  The below date gets
    //rounded to 513, so we need to construct a JulianDate directly.
    var expectedDate = new JulianDate(2455045, 1825.5125423, TimeStandard.UTC);
    var computedDate = JulianDate.fromIso8601("2009-08-01T12:30:25.5125423Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it('Construct from ISO8601 UTC calendar date and time fractional seconds, basic format, "," instead of "."', function () {
    //Date is only accurate to milliseconds, while JulianDate, much more so.  The below date gets
    //rounded to 513, so we need to construct a JulianDate directly.
    //var expectedDate = JulianDate.fromDate(new Date(Date.UTC(2009, 7, 1, 12, 30, 25, 5125423)));
    var expectedDate = new JulianDate(2455045, 1825.5125423, TimeStandard.UTC);
    var computedDate = JulianDate.fromIso8601("20090801T123025,5125423Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it('Construct from ISO8601 UTC calendar date and time fractional seconds, extended format, "," instead of "."', function () {
    //Date is only accurate to milliseconds, while JulianDate, much more so.  The below date gets
    //rounded to 513, so we need to construct a JulianDate directly.
    var expectedDate = new JulianDate(2455045, 1825.5125423, TimeStandard.UTC);
    var computedDate = JulianDate.fromIso8601("2009-08-01T12:30:25,5125423Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time no seconds, basic format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("20090801T1230Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time no seconds, extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T12:30Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time fractional minutes, basic format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 30))
    );
    var computedDate = JulianDate.fromIso8601("20090801T1230.5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time fractional minutes, extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 30))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T12:30.5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it('Construct from ISO8601 UTC calendar date and time fractional minutes, basic format, "," instead of "."', function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 30))
    );
    var computedDate = JulianDate.fromIso8601("20090801T1230,5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it('Construct from ISO8601 UTC calendar date and time fractional minutes, extended format, "," instead of "."', function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 30))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T12:30,5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time no minutes/seconds, basic format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 0, 0))
    );
    var computedDate = JulianDate.fromIso8601("20090801T12Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time no minutes/seconds, extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 0, 0))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T12Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time fractional hours, basic format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("20090801T12.5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 UTC calendar date and time fractional hours, extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T12.5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it('Construct from ISO8601 UTC calendar date and time fractional hours, basic format, "," instead of "."', function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("20090801T12,5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it('Construct from ISO8601 UTC calendar date and time fractional hours, extended format, "," instead of "."', function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T12,5Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 UTC calendar date and time on a leap second", function () {
    var computedDate = JulianDate.fromIso8601("2008-12-31T23:59:60Z");
    var expectedDate = new JulianDate(2454832, 43233, TimeStandard.TAI);
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 UTC calendar date and time within a leap second", function () {
    var computedDate = JulianDate.fromIso8601("2008-12-31T23:59:60.123456789Z");
    var expectedDate = new JulianDate(
      2454832,
      43233.123456789,
      TimeStandard.TAI
    );
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date and time on a leap second 1 hour behind UTC", function () {
    var computedDate = JulianDate.fromIso8601("2008-12-31T22:59:60-01");
    var expectedDate = new JulianDate(2454832, 43233, TimeStandard.TAI);
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date and time on a leap second 1 hour ahead of UTC", function () {
    var computedDate = JulianDate.fromIso8601("2009-01-01T00:59:60+01");
    var expectedDate = new JulianDate(2454832, 43233, TimeStandard.TAI);
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 calendar date and time using 24:00:00 midnight notation", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 2, 0, 0, 0))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T24:00:00Z");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with UTC offset that crosses into previous month", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(1985, 2, 31, 23, 59, 0))
    );
    var computedDate = JulianDate.fromIso8601("1985-04-01T00:59:00+01");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with UTC offset that crosses into next month", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(1985, 3, 1, 0, 59, 0))
    );
    var computedDate = JulianDate.fromIso8601("1985-03-31T23:59:00-01");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with UTC offset that crosses into next year", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2008, 11, 31, 23, 0, 0))
    );
    var julianDate = JulianDate.fromIso8601("2009-01-01T01:00:00+02");
    expect(julianDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with UTC offset that crosses into previous year", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 0, 1, 1, 0, 0))
    );
    var julianDate = JulianDate.fromIso8601("2008-12-31T23:00:00-02");
    expect(julianDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with UTC offset", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2008, 10, 10, 12, 0, 0))
    );
    var julianDate = JulianDate.fromIso8601("2008-11-10T14:00:00+02");
    expect(julianDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with UTC offset in extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2008, 10, 10, 11, 30, 0))
    );
    var julianDate = JulianDate.fromIso8601("2008-11-10T14:00:00+02:30");
    expect(julianDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with zero UTC offset in extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2008, 10, 10, 14, 0, 0))
    );
    var julianDate = JulianDate.fromIso8601("2008-11-10T14:00:00+00:00");
    expect(julianDate).toEqual(expectedDate);
  });
 
  it("Construct from an ISO8601 local calendar date with zero UTC offset in extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2008, 10, 10, 14, 0, 0))
    );
    var julianDate = JulianDate.fromIso8601("2008-11-10T14:00:00+00");
    expect(julianDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 local calendar date and time with no seconds and UTC offset in basic format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("20090801T0730-0500");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Construct from ISO8601 local calendar date and time with no seconds and UTC offset in extended format", function () {
    var expectedDate = JulianDate.fromDate(
      new Date(Date.UTC(2009, 7, 1, 12, 30, 0))
    );
    var computedDate = JulianDate.fromIso8601("2009-08-01T07:30-05:00");
    expect(computedDate).toEqual(expectedDate);
  });
 
  it("Fails to construct an ISO8601 ordinal date with day less than 1", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-000");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 ordinal date with day more than 365 on non-leap year", function () {
    expect(function () {
      return JulianDate.fromIso8601("2001-366");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct ISO8601 UTC calendar date of invalid YYMMDD format", function () {
    expect(function () {
      return JulianDate.fromIso8601("200905");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct a complete ISO8601 date missing T delimeter", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-08-0112:30.5Z");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct a complete ISO8601 date with delimeter other than T", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-08-01Q12:30.5Z");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date from undefined", function () {
    expect(function () {
      return JulianDate.fromIso8601(undefined);
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 from complete garbage", function () {
    expect(function () {
      return JulianDate.fromIso8601("this is not a date");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date from a valid ISO8601 interval", function () {
    expect(function () {
      return JulianDate.fromIso8601(
        "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
      );
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct from an ISO8601 with too many year digits", function () {
    expect(function () {
      return JulianDate.fromIso8601("20091-05-19");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct from an ISO8601 with too many month digits", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-100-19");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct from an ISO8601 with more than 12 months", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-13-19");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct from an ISO8601 with less than 1 months", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-00-19");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 January date with more than 31 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-01-32");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 Febuary date with more than 28 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-02-29");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 Febuary leap year date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-02-30");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 March date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-03-32");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 April date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-04-31");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 May date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-05-32");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 June date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-06-31");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 July date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-07-32");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 August date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-08-32");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 September date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-09-31");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 October date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-10-32");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 November date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-11-31");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 December date with more than 29 days", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-32");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date with more than 24 hours (extra seconds)", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T24:00:01");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date with more than 24 hours (extra minutes)", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T24:01:00");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date with more than 59 minutes", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T12:60");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date with more than 60 seconds", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T12:59:61");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct from an ISO8601 with less than 1 day", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009-01-00");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct from an ISO8601 with too many dashes", function () {
    expect(function () {
      return JulianDate.fromIso8601("2009--01-01");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct from an ISO8601 with garbage offset", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T12:59:23ZZ+-050708::1234");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date with more than one decimal place", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T12:59:22..2");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 calendar date mixing basic and extended format", function () {
    expect(function () {
      return JulianDate.fromIso8601("200108-01");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 calendar date mixing basic and extended format", function () {
    expect(function () {
      return JulianDate.fromIso8601("2001-0801");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 calendar week mixing basic and extended format", function () {
    expect(function () {
      return JulianDate.fromIso8601("2008-W396");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 calendar week mixing basic and extended format", function () {
    expect(function () {
      return JulianDate.fromIso8601("2008W39-6");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 date with trailing -", function () {
    expect(function () {
      return JulianDate.fromIso8601("2001-");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 time mixing basic and extended format", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T22:0100");
    }).toThrowDeveloperError();
  });
 
  it("Fails to construct an ISO8601 time mixing basic and extended format", function () {
    expect(function () {
      return JulianDate.fromIso8601("2000-12-15T2201:00");
    }).toThrowDeveloperError();
  });
 
  it("toDate works when using TAI", function () {
    var julianDateTai = new JulianDate(2455927.157772, 0, TimeStandard.UTC);
    var javascriptDate = JulianDate.toDate(julianDateTai);
    expect(javascriptDate.getUTCFullYear()).toEqual(2011);
    expect(javascriptDate.getUTCMonth()).toEqual(11);
    expect(javascriptDate.getUTCDate()).toEqual(31);
    expect(javascriptDate.getUTCHours()).toEqual(15);
    expect(javascriptDate.getUTCMinutes()).toEqual(47);
    expect(javascriptDate.getUTCSeconds()).toEqual(11);
    expect(javascriptDate.getUTCMilliseconds()).toEqualEpsilon(500, 10);
  });
 
  it("toDate works a second before a leap second", function () {
    var expectedDate = new Date("6/30/1997 11:59:59 PM UTC");
    var date = JulianDate.toDate(
      new JulianDate(2450630, 43229.0, TimeStandard.TAI)
    );
    expect(date).toEqual(expectedDate);
  });
 
  it("toDate works on a leap second", function () {
    var expectedDate = new Date("6/30/1997 11:59:59 PM UTC");
    var date = JulianDate.toDate(
      new JulianDate(2450630, 43230.0, TimeStandard.TAI)
    );
    expect(date).toEqual(expectedDate);
  });
 
  it("toDate works a second after a leap second", function () {
    var expectedDate = new Date("7/1/1997 12:00:00 AM UTC");
    var date = JulianDate.toDate(
      new JulianDate(2450630, 43231.0, TimeStandard.TAI)
    );
    expect(date).toEqual(expectedDate);
  });
 
  it("toDate works on date before any leap seconds", function () {
    var expectedDate = new Date("09/10/1968 12:00:00 AM UTC");
    var date = JulianDate.toDate(
      new JulianDate(2440109, 43210.0, TimeStandard.TAI)
    );
    expect(date).toEqual(expectedDate);
  });
 
  it("toDate works on date later than all leap seconds", function () {
    var expectedDate = new Date("11/17/2039 12:00:00 AM UTC");
    var date = JulianDate.toDate(
      new JulianDate(2466109, 43237.0, TimeStandard.TAI)
    );
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 works a second before a leap second", function () {
    var expectedDate = "1997-06-30T23:59:59Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate));
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 works on a leap second", function () {
    var expectedDate = "1997-06-30T23:59:60Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate));
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 works a second after a leap second", function () {
    var expectedDate = "1997-07-01T00:00:00Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate));
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 works on date before any leap seconds", function () {
    var expectedDate = "1968-09-10T00:00:00Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate));
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 works on date later than all leap seconds", function () {
    var expectedDate = "2031-11-17T00:00:00Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate));
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 works without precision", function () {
    var expectedDate = "0950-01-02T03:04:05.5Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate));
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 pads zeros for year less than four digits or time components less than two digits", function () {
    var expectedDate = "0950-01-02T03:04:05.005Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate), 3);
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 does not show milliseconds if they are 0", function () {
    var expectedDate = "0950-01-02T03:04:05Z";
    var date = JulianDate.toIso8601(JulianDate.fromIso8601(expectedDate));
    expect(date).toEqual(expectedDate);
  });
 
  it("toIso8601 works with specified precision", function () {
    var isoDate = "0950-01-02T03:04:05.012345Z";
    var date;
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 0);
    expect(date).toEqual("0950-01-02T03:04:05Z");
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 1);
    expect(date).toEqual("0950-01-02T03:04:05.0Z");
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 2);
    expect(date).toEqual("0950-01-02T03:04:05.01Z");
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 3);
    expect(date).toEqual("0950-01-02T03:04:05.012Z");
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 4);
    expect(date).toEqual("0950-01-02T03:04:05.0123Z");
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 5);
    expect(date).toEqual("0950-01-02T03:04:05.01234Z");
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 6);
    expect(date).toEqual("0950-01-02T03:04:05.012345Z");
    date = JulianDate.toIso8601(JulianDate.fromIso8601(isoDate), 7);
    expect(date).toEqual("0950-01-02T03:04:05.0123450Z");
  });
 
  it("can format Iso8601.MINIMUM_VALUE and MAXIMUM_VALUE to ISO strings", function () {
    var minString = Iso8601.MINIMUM_VALUE.toString();
    expect(minString).toEqual("0000-01-01T00:00:00Z");
    expect(JulianDate.fromIso8601(minString)).toEqual(Iso8601.MINIMUM_VALUE);
 
    var maxString = Iso8601.MAXIMUM_VALUE.toString();
    expect(maxString).toEqual("9999-12-31T24:00:00Z");
    expect(JulianDate.fromIso8601(maxString)).toEqual(Iso8601.MAXIMUM_VALUE);
  });
 
  it("secondsDifference works in UTC", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.fromDate(new Date("July 5, 2011 12:01:00 UTC"));
    expect(JulianDate.secondsDifference(end, start)).toEqualEpsilon(
      TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE,
      CesiumMath.EPSILON5
    );
  });
 
  it("secondsDifference works in TAI", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.fromDate(new Date("July 5, 2011 12:01:00 UTC"));
    expect(JulianDate.secondsDifference(end, start)).toEqualEpsilon(
      TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE,
      CesiumMath.EPSILON5
    );
  });
 
  it("secondsDifference works with mixed time standards", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.fromDate(new Date("July 5, 2011 12:01:00 UTC"));
    expect(JulianDate.secondsDifference(end, start)).toEqualEpsilon(
      TimeConstants.SECONDS_PER_DAY + TimeConstants.SECONDS_PER_MINUTE,
      CesiumMath.EPSILON5
    );
  });
 
  it("daysDifference works", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00"));
    var end = JulianDate.fromDate(new Date("July 5, 2011 14:24:00"));
    var difference = JulianDate.daysDifference(end, start);
    expect(difference).toEqual(1.1);
  });
 
  it("daysDifference works with negative result", function () {
    var end = JulianDate.fromDate(new Date("July 4, 2011 12:00:00"));
    var start = JulianDate.fromDate(new Date("July 5, 2011 14:24:00"));
    var difference = JulianDate.daysDifference(end, start);
    expect(difference).toEqual(-1.1);
  });
 
  it("addSeconds works with whole seconds", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:30 UTC"));
    var end = JulianDate.addSeconds(start, 95, new JulianDate());
    expect(JulianDate.toDate(end).getUTCSeconds()).toEqualEpsilon(
      5,
      CesiumMath.EPSILON5
    );
    expect(JulianDate.toDate(end).getUTCMinutes()).toEqualEpsilon(
      2,
      CesiumMath.EPSILON5
    );
  });
 
  it("addSeconds works with fractions (1)", function () {
    var start = new JulianDate(2454832, 0, TimeStandard.TAI);
    var end = JulianDate.addSeconds(start, 1.5, new JulianDate());
    expect(JulianDate.secondsDifference(end, start)).toEqual(1.5);
  });
 
  it("addSeconds works with fractions (2)", function () {
    var start = JulianDate.fromDate(new Date("August 11 2011 6:00:00 UTC"));
    var end = JulianDate.addSeconds(start, 0.5, new JulianDate());
    expect(JulianDate.secondsDifference(end, start, new JulianDate())).toEqual(
      0.5
    );
  });
 
  it("addSeconds works with fractions (3)", function () {
    var start = JulianDate.fromDate(new Date("August 11 2011 11:59:59 UTC"));
    var end = JulianDate.addSeconds(start, 1.25, new JulianDate());
    expect(JulianDate.secondsDifference(end, start, new JulianDate())).toEqual(
      1.25
    );
  });
 
  it("addSeconds works with negative numbers", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:01:30 UTC"));
    var end = JulianDate.addSeconds(start, -60.0, new JulianDate());
    expect(JulianDate.secondsDifference(end, start)).toEqual(-60.0);
  });
 
  it("addSeconds works with more seconds than in a day", function () {
    var seconds = TimeConstants.SECONDS_PER_DAY * 7 + 15;
    var start = new JulianDate(2448444, 0, TimeStandard.UTC);
    var end = JulianDate.addSeconds(start, seconds, new JulianDate());
    expect(JulianDate.secondsDifference(end, start)).toEqual(seconds);
  });
 
  it("addSeconds works with negative seconds more than in a day", function () {
    var seconds = -TimeConstants.SECONDS_PER_DAY * 7 - 15;
    var start = new JulianDate(2448444, 0, TimeStandard.UTC);
    var end = JulianDate.addSeconds(start, seconds, new JulianDate());
    expect(JulianDate.secondsDifference(end, start)).toEqual(seconds);
  });
  it("addSeconds fails with undefined input", function () {
    expect(function () {
      return JulianDate.addSeconds(
        JulianDate.now(),
        undefined,
        new JulianDate()
      );
    }).toThrowDeveloperError();
  });
  it("addMinutes works", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.addMinutes(start, 65, new JulianDate());
    expect(JulianDate.toDate(end).getUTCMinutes()).toEqualEpsilon(
      5,
      CesiumMath.EPSILON5
    );
    expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(
      13,
      CesiumMath.EPSILON5
    );
  });
 
  it("addMinutes works with negative numbers", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.addMinutes(start, -35, new JulianDate());
    expect(JulianDate.toDate(end).getUTCMinutes()).toEqualEpsilon(
      25,
      CesiumMath.EPSILON5
    );
    expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(
      11,
      CesiumMath.EPSILON5
    );
  });
 
  it("addMinutes fails with undefined input", function () {
    expect(function () {
      return JulianDate.addMinutes(
        JulianDate.now(),
        undefined,
        new JulianDate()
      );
    }).toThrowDeveloperError();
  });
 
  it("addHours works", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.addHours(start, 6, new JulianDate());
    expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(
      18,
      CesiumMath.EPSILON5
    );
  });
 
  it("addHours works with negative numbers", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.addHours(start, -6, new JulianDate());
    expect(JulianDate.toDate(end).getUTCHours()).toEqualEpsilon(
      6,
      CesiumMath.EPSILON5
    );
  });
  it("addHours fails with undefined input", function () {
    expect(function () {
      return JulianDate.addHours(JulianDate.now(), undefined, new JulianDate());
    }).toThrowDeveloperError();
  });
 
  it("addDays works", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.addDays(start, 32, new JulianDate());
    expect(JulianDate.toDate(end).getUTCDate()).toEqualEpsilon(
      5,
      CesiumMath.EPSILON5
    );
    expect(JulianDate.toDate(end).getUTCMonth()).toEqualEpsilon(
      7,
      CesiumMath.EPSILON5
    );
  });
 
  it("addDays works with negative numbers", function () {
    var start = JulianDate.fromDate(new Date("July 4, 2011 12:00:00 UTC"));
    var end = JulianDate.addDays(start, -4, new JulianDate());
    expect(JulianDate.toDate(end).getUTCDate()).toEqualEpsilon(
      30,
      CesiumMath.EPSILON5
    );
    expect(JulianDate.toDate(end).getUTCMonth()).toEqualEpsilon(
      5,
      CesiumMath.EPSILON5
    );
  });
 
  it("addDays fails with undefined input", function () {
    expect(function () {
      return JulianDate.addDays(JulianDate.now(), undefined, new JulianDate());
    }).toThrowDeveloperError();
  });
 
  it("lessThan works", function () {
    var start = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    var end = JulianDate.fromDate(new Date("July 6, 2011 12:01:00"));
    expect(JulianDate.lessThan(start, end)).toEqual(true);
  });
 
  it("lessThan works with equal values", function () {
    var start = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    var end = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    expect(JulianDate.lessThan(start, end)).toEqual(false);
    expect(
      JulianDate.lessThan(
        start,
        JulianDate.addSeconds(end, 1, new JulianDate())
      )
    ).toEqual(true);
  });
 
  it("lessThan works with different time standards", function () {
    var start = new JulianDate(0, 0, TimeStandard.TAI);
    var end = new JulianDate(0, 0, TimeStandard.UTC);
    expect(JulianDate.lessThan(start, end)).toEqual(true);
  });
 
  it("lessThanOrEquals works", function () {
    var start = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    var end = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    expect(JulianDate.lessThanOrEquals(start, end)).toEqual(true);
    expect(
      JulianDate.lessThanOrEquals(
        JulianDate.addSeconds(start, 1, new JulianDate()),
        end
      )
    ).toEqual(false);
    expect(
      JulianDate.lessThanOrEquals(
        JulianDate.addSeconds(start, -1, new JulianDate()),
        end
      )
    ).toEqual(true);
  });
 
  it("greaterThan works", function () {
    var start = JulianDate.fromDate(new Date("July 6, 2011 12:01:00"));
    var end = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    expect(JulianDate.greaterThan(start, end)).toEqual(true);
  });
 
  it("greaterThan works with equal values", function () {
    var start = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    var end = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    expect(JulianDate.greaterThan(start, end)).toEqual(false);
    expect(
      JulianDate.greaterThan(
        start,
        JulianDate.addSeconds(end, -1, new JulianDate())
      )
    ).toEqual(true);
  });
 
  it("greaterThan works with different time standards", function () {
    var start = new JulianDate(0, 0, TimeStandard.UTC);
    var end = new JulianDate(0, 0, TimeStandard.TAI);
    expect(JulianDate.greaterThan(start, end)).toEqual(true);
  });
 
  it("greaterThanOrEquals works", function () {
    var start = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    var end = JulianDate.fromDate(new Date("July 6, 1991 12:00:00"));
    expect(JulianDate.greaterThanOrEquals(start, end)).toEqual(true);
    expect(
      JulianDate.greaterThanOrEquals(
        JulianDate.addSeconds(start, -1, new JulianDate()),
        end
      )
    ).toEqual(false);
    expect(
      JulianDate.greaterThanOrEquals(
        JulianDate.addSeconds(start, 1, new JulianDate()),
        end
      )
    ).toEqual(true);
  });
 
  it("can be equal to within an epsilon of another JulianDate", function () {
    var original = JulianDate.fromDate(
      new Date("September 7, 2011 12:55:00 UTC")
    );
    var clone = JulianDate.fromDate(new Date("September 7, 2011 12:55:00 UTC"));
    clone = JulianDate.addSeconds(clone, 1, new JulianDate());
    expect(original.equalsEpsilon(clone, 2)).toEqual(true);
  });
 
  it("totalDays works", function () {
    var totalDays = 2455784.7500058;
    var original = new JulianDate(totalDays, 0, TimeStandard.TAI);
    expect(totalDays).toEqual(JulianDate.totalDays(original));
  });
 
  it("equalsEpsilon works", function () {
    var date = JulianDate.now();
    var datePlusOne = JulianDate.addSeconds(date, 0.01, new JulianDate());
    expect(date.equalsEpsilon(datePlusOne, CesiumMath.EPSILON1)).toEqual(true);
  });
 
  it("formats as ISO8601 with toString", function () {
    var date = JulianDate.now();
    expect(date.toString()).toEqual(JulianDate.toIso8601(date));
  });
 
  it("computeTaiMinusUtc works before all leap seconds", function () {
    var date = new Date("July 11, 1970 12:00:00 UTC");
    var jd = JulianDate.fromDate(date);
    var difference = JulianDate.computeTaiMinusUtc(jd);
    expect(difference).toEqual(10);
  });
 
  it("computeTaiMinusUtc works a second before a leap second", function () {
    var date = new JulianDate(2456109, 43233.0, TimeStandard.TAI);
    expect(JulianDate.computeTaiMinusUtc(date)).toEqual(34);
  });
 
  it("computeTaiMinusUtc works on a leap second", function () {
    var date = new JulianDate(2456109, 43234.0, TimeStandard.TAI);
    expect(JulianDate.computeTaiMinusUtc(date)).toEqual(34);
  });
 
  it("computeTaiMinusUtc works a second after a leap second", function () {
    var date = new JulianDate(2456109, 43235.0, TimeStandard.TAI);
    expect(JulianDate.computeTaiMinusUtc(date)).toEqual(35);
  });
 
  it("computeTaiMinusUtc works after all leap seconds", function () {
    var date = new JulianDate(2556109, 43237.0, TimeStandard.TAI);
    expect(JulianDate.computeTaiMinusUtc(date)).toEqual(37);
  });
 
  it("fromGregorianDate returns the same date", function () {
    var iso86011 = "2017-01-01T10:01:01.5Z";
    var julian1 = JulianDate.fromIso8601(iso86011);
    var gregorian = JulianDate.toGregorianDate(julian1);
    var julian2 = JulianDate.fromGregorianDate(gregorian);
    var iso86012 = JulianDate.toIso8601(julian2);
 
    expect(iso86011).toEqual(iso86012);
    expect(JulianDate.compare(julian1, julian2)).toEqual(0);
  });
});