mscorlib(4.0.0.0) API with additions
HebrewCalendar.cs
2 
3 namespace System.Globalization
4 {
7  [ComVisible(true)]
8  public class HebrewCalendar : Calendar
9  {
10  internal class __DateBuffer
11  {
12  internal int year;
13 
14  internal int month;
15 
16  internal int day;
17  }
18 
20  public static readonly int HebrewEra = 1;
21 
22  internal const int DatePartYear = 0;
23 
24  internal const int DatePartDayOfYear = 1;
25 
26  internal const int DatePartMonth = 2;
27 
28  internal const int DatePartDay = 3;
29 
30  internal const int DatePartDayOfWeek = 4;
31 
32  private const int HebrewYearOf1AD = 3760;
33 
34  private const int FirstGregorianTableYear = 1583;
35 
36  private const int LastGregorianTableYear = 2239;
37 
38  private const int TABLESIZE = 656;
39 
40  private const int MinHebrewYear = 5343;
41 
42  private const int MaxHebrewYear = 5999;
43 
44  private static readonly int[] HebrewTable = new int[1316]
45  {
46  7,
47  3,
48  17,
49  3,
50  0,
51  4,
52  11,
53  2,
54  21,
55  6,
56  1,
57  3,
58  13,
59  2,
60  25,
61  4,
62  5,
63  3,
64  16,
65  2,
66  27,
67  6,
68  9,
69  1,
70  20,
71  2,
72  0,
73  6,
74  11,
75  3,
76  23,
77  4,
78  4,
79  2,
80  14,
81  3,
82  27,
83  4,
84  8,
85  2,
86  18,
87  3,
88  28,
89  6,
90  11,
91  1,
92  22,
93  5,
94  2,
95  3,
96  12,
97  3,
98  25,
99  4,
100  6,
101  2,
102  16,
103  3,
104  26,
105  6,
106  8,
107  2,
108  20,
109  1,
110  0,
111  6,
112  11,
113  2,
114  24,
115  4,
116  4,
117  3,
118  15,
119  2,
120  25,
121  6,
122  8,
123  1,
124  19,
125  2,
126  29,
127  6,
128  9,
129  3,
130  22,
131  4,
132  3,
133  2,
134  13,
135  3,
136  25,
137  4,
138  6,
139  3,
140  17,
141  2,
142  27,
143  6,
144  7,
145  3,
146  19,
147  2,
148  31,
149  4,
150  11,
151  3,
152  23,
153  4,
154  5,
155  2,
156  15,
157  3,
158  25,
159  6,
160  6,
161  2,
162  19,
163  1,
164  29,
165  6,
166  10,
167  2,
168  22,
169  4,
170  3,
171  3,
172  14,
173  2,
174  24,
175  6,
176  6,
177  1,
178  17,
179  3,
180  28,
181  5,
182  8,
183  3,
184  20,
185  1,
186  32,
187  5,
188  12,
189  3,
190  22,
191  6,
192  4,
193  1,
194  16,
195  2,
196  26,
197  6,
198  6,
199  3,
200  17,
201  2,
202  0,
203  4,
204  10,
205  3,
206  22,
207  4,
208  3,
209  2,
210  14,
211  3,
212  24,
213  6,
214  5,
215  2,
216  17,
217  1,
218  28,
219  6,
220  9,
221  2,
222  19,
223  3,
224  31,
225  4,
226  13,
227  2,
228  23,
229  6,
230  3,
231  3,
232  15,
233  1,
234  27,
235  5,
236  7,
237  3,
238  17,
239  3,
240  29,
241  4,
242  11,
243  2,
244  21,
245  6,
246  3,
247  1,
248  14,
249  2,
250  25,
251  6,
252  5,
253  3,
254  16,
255  2,
256  28,
257  4,
258  9,
259  3,
260  20,
261  2,
262  0,
263  6,
264  12,
265  1,
266  23,
267  6,
268  4,
269  2,
270  14,
271  3,
272  26,
273  4,
274  8,
275  2,
276  18,
277  3,
278  0,
279  4,
280  10,
281  3,
282  21,
283  5,
284  1,
285  3,
286  13,
287  1,
288  24,
289  5,
290  5,
291  3,
292  15,
293  3,
294  27,
295  4,
296  8,
297  2,
298  19,
299  3,
300  29,
301  6,
302  10,
303  2,
304  22,
305  4,
306  3,
307  3,
308  14,
309  2,
310  26,
311  4,
312  6,
313  3,
314  18,
315  2,
316  28,
317  6,
318  10,
319  1,
320  20,
321  6,
322  2,
323  2,
324  12,
325  3,
326  24,
327  4,
328  5,
329  2,
330  16,
331  3,
332  28,
333  4,
334  8,
335  3,
336  19,
337  2,
338  0,
339  6,
340  12,
341  1,
342  23,
343  5,
344  3,
345  3,
346  14,
347  3,
348  26,
349  4,
350  7,
351  2,
352  17,
353  3,
354  28,
355  6,
356  9,
357  2,
358  21,
359  4,
360  1,
361  3,
362  13,
363  2,
364  25,
365  4,
366  5,
367  3,
368  16,
369  2,
370  27,
371  6,
372  9,
373  1,
374  19,
375  3,
376  0,
377  5,
378  11,
379  3,
380  23,
381  4,
382  4,
383  2,
384  14,
385  3,
386  25,
387  6,
388  7,
389  1,
390  18,
391  2,
392  28,
393  6,
394  9,
395  3,
396  21,
397  4,
398  2,
399  2,
400  12,
401  3,
402  25,
403  4,
404  6,
405  2,
406  16,
407  3,
408  26,
409  6,
410  8,
411  2,
412  20,
413  1,
414  0,
415  6,
416  11,
417  2,
418  22,
419  6,
420  4,
421  1,
422  15,
423  2,
424  25,
425  6,
426  6,
427  3,
428  18,
429  1,
430  29,
431  5,
432  9,
433  3,
434  22,
435  4,
436  2,
437  3,
438  13,
439  2,
440  23,
441  6,
442  4,
443  3,
444  15,
445  2,
446  27,
447  4,
448  7,
449  3,
450  19,
451  2,
452  31,
453  4,
454  11,
455  3,
456  21,
457  6,
458  3,
459  2,
460  15,
461  1,
462  25,
463  6,
464  6,
465  2,
466  17,
467  3,
468  29,
469  4,
470  10,
471  2,
472  20,
473  6,
474  3,
475  1,
476  13,
477  3,
478  24,
479  5,
480  4,
481  3,
482  16,
483  1,
484  27,
485  5,
486  7,
487  3,
488  17,
489  3,
490  0,
491  4,
492  11,
493  2,
494  21,
495  6,
496  1,
497  3,
498  13,
499  2,
500  25,
501  4,
502  5,
503  3,
504  16,
505  2,
506  29,
507  4,
508  9,
509  3,
510  19,
511  6,
512  30,
513  2,
514  13,
515  1,
516  23,
517  6,
518  4,
519  2,
520  14,
521  3,
522  27,
523  4,
524  8,
525  2,
526  18,
527  3,
528  0,
529  4,
530  11,
531  3,
532  22,
533  5,
534  2,
535  3,
536  14,
537  1,
538  26,
539  5,
540  6,
541  3,
542  16,
543  3,
544  28,
545  4,
546  10,
547  2,
548  20,
549  6,
550  30,
551  3,
552  11,
553  2,
554  24,
555  4,
556  4,
557  3,
558  15,
559  2,
560  25,
561  6,
562  8,
563  1,
564  19,
565  2,
566  29,
567  6,
568  9,
569  3,
570  22,
571  4,
572  3,
573  2,
574  13,
575  3,
576  25,
577  4,
578  7,
579  2,
580  17,
581  3,
582  27,
583  6,
584  9,
585  1,
586  21,
587  5,
588  1,
589  3,
590  11,
591  3,
592  23,
593  4,
594  5,
595  2,
596  15,
597  3,
598  25,
599  6,
600  6,
601  2,
602  19,
603  1,
604  29,
605  6,
606  10,
607  2,
608  22,
609  4,
610  3,
611  3,
612  14,
613  2,
614  24,
615  6,
616  6,
617  1,
618  18,
619  2,
620  28,
621  6,
622  8,
623  3,
624  20,
625  4,
626  2,
627  2,
628  12,
629  3,
630  24,
631  4,
632  4,
633  3,
634  16,
635  2,
636  26,
637  6,
638  6,
639  3,
640  17,
641  2,
642  0,
643  4,
644  10,
645  3,
646  22,
647  4,
648  3,
649  2,
650  14,
651  3,
652  24,
653  6,
654  5,
655  2,
656  17,
657  1,
658  28,
659  6,
660  9,
661  2,
662  21,
663  4,
664  1,
665  3,
666  13,
667  2,
668  23,
669  6,
670  5,
671  1,
672  15,
673  3,
674  27,
675  5,
676  7,
677  3,
678  19,
679  1,
680  0,
681  5,
682  10,
683  3,
684  22,
685  4,
686  2,
687  3,
688  13,
689  2,
690  24,
691  6,
692  4,
693  3,
694  15,
695  2,
696  27,
697  4,
698  8,
699  3,
700  20,
701  4,
702  1,
703  2,
704  11,
705  3,
706  22,
707  6,
708  3,
709  2,
710  15,
711  1,
712  25,
713  6,
714  7,
715  2,
716  17,
717  3,
718  29,
719  4,
720  10,
721  2,
722  21,
723  6,
724  1,
725  3,
726  13,
727  1,
728  24,
729  5,
730  5,
731  3,
732  15,
733  3,
734  27,
735  4,
736  8,
737  2,
738  19,
739  6,
740  1,
741  1,
742  12,
743  2,
744  22,
745  6,
746  3,
747  3,
748  14,
749  2,
750  26,
751  4,
752  6,
753  3,
754  18,
755  2,
756  28,
757  6,
758  10,
759  1,
760  20,
761  6,
762  2,
763  2,
764  12,
765  3,
766  24,
767  4,
768  5,
769  2,
770  16,
771  3,
772  28,
773  4,
774  9,
775  2,
776  19,
777  6,
778  30,
779  3,
780  12,
781  1,
782  23,
783  5,
784  3,
785  3,
786  14,
787  3,
788  26,
789  4,
790  7,
791  2,
792  17,
793  3,
794  28,
795  6,
796  9,
797  2,
798  21,
799  4,
800  1,
801  3,
802  13,
803  2,
804  25,
805  4,
806  5,
807  3,
808  16,
809  2,
810  27,
811  6,
812  9,
813  1,
814  19,
815  6,
816  30,
817  2,
818  11,
819  3,
820  23,
821  4,
822  4,
823  2,
824  14,
825  3,
826  27,
827  4,
828  7,
829  3,
830  18,
831  2,
832  28,
833  6,
834  11,
835  1,
836  22,
837  5,
838  2,
839  3,
840  12,
841  3,
842  25,
843  4,
844  6,
845  2,
846  16,
847  3,
848  26,
849  6,
850  8,
851  2,
852  20,
853  4,
854  30,
855  3,
856  11,
857  2,
858  24,
859  4,
860  4,
861  3,
862  15,
863  2,
864  25,
865  6,
866  8,
867  1,
868  18,
869  3,
870  29,
871  5,
872  9,
873  3,
874  22,
875  4,
876  3,
877  2,
878  13,
879  3,
880  23,
881  6,
882  6,
883  1,
884  17,
885  2,
886  27,
887  6,
888  7,
889  3,
890  20,
891  4,
892  1,
893  2,
894  11,
895  3,
896  23,
897  4,
898  5,
899  2,
900  15,
901  3,
902  25,
903  6,
904  6,
905  2,
906  19,
907  1,
908  29,
909  6,
910  10,
911  2,
912  20,
913  6,
914  3,
915  1,
916  14,
917  2,
918  24,
919  6,
920  4,
921  3,
922  17,
923  1,
924  28,
925  5,
926  8,
927  3,
928  20,
929  4,
930  1,
931  3,
932  12,
933  2,
934  22,
935  6,
936  2,
937  3,
938  14,
939  2,
940  26,
941  4,
942  6,
943  3,
944  17,
945  2,
946  0,
947  4,
948  10,
949  3,
950  20,
951  6,
952  1,
953  2,
954  14,
955  1,
956  24,
957  6,
958  5,
959  2,
960  15,
961  3,
962  28,
963  4,
964  9,
965  2,
966  19,
967  6,
968  1,
969  1,
970  12,
971  3,
972  23,
973  5,
974  3,
975  3,
976  15,
977  1,
978  27,
979  5,
980  7,
981  3,
982  17,
983  3,
984  29,
985  4,
986  11,
987  2,
988  21,
989  6,
990  1,
991  3,
992  12,
993  2,
994  25,
995  4,
996  5,
997  3,
998  16,
999  2,
1000  28,
1001  4,
1002  9,
1003  3,
1004  19,
1005  6,
1006  30,
1007  2,
1008  12,
1009  1,
1010  23,
1011  6,
1012  4,
1013  2,
1014  14,
1015  3,
1016  26,
1017  4,
1018  8,
1019  2,
1020  18,
1021  3,
1022  0,
1023  4,
1024  10,
1025  3,
1026  22,
1027  5,
1028  2,
1029  3,
1030  14,
1031  1,
1032  25,
1033  5,
1034  6,
1035  3,
1036  16,
1037  3,
1038  28,
1039  4,
1040  9,
1041  2,
1042  20,
1043  6,
1044  30,
1045  3,
1046  11,
1047  2,
1048  23,
1049  4,
1050  4,
1051  3,
1052  15,
1053  2,
1054  27,
1055  4,
1056  7,
1057  3,
1058  19,
1059  2,
1060  29,
1061  6,
1062  11,
1063  1,
1064  21,
1065  6,
1066  3,
1067  2,
1068  13,
1069  3,
1070  25,
1071  4,
1072  6,
1073  2,
1074  17,
1075  3,
1076  27,
1077  6,
1078  9,
1079  1,
1080  20,
1081  5,
1082  30,
1083  3,
1084  10,
1085  3,
1086  22,
1087  4,
1088  3,
1089  2,
1090  14,
1091  3,
1092  24,
1093  6,
1094  5,
1095  2,
1096  17,
1097  1,
1098  28,
1099  6,
1100  9,
1101  2,
1102  21,
1103  4,
1104  1,
1105  3,
1106  13,
1107  2,
1108  23,
1109  6,
1110  5,
1111  1,
1112  16,
1113  2,
1114  27,
1115  6,
1116  7,
1117  3,
1118  19,
1119  4,
1120  30,
1121  2,
1122  11,
1123  3,
1124  23,
1125  4,
1126  3,
1127  3,
1128  14,
1129  2,
1130  25,
1131  6,
1132  5,
1133  3,
1134  16,
1135  2,
1136  28,
1137  4,
1138  9,
1139  3,
1140  21,
1141  4,
1142  2,
1143  2,
1144  12,
1145  3,
1146  23,
1147  6,
1148  4,
1149  2,
1150  16,
1151  1,
1152  26,
1153  6,
1154  8,
1155  2,
1156  20,
1157  4,
1158  30,
1159  3,
1160  11,
1161  2,
1162  22,
1163  6,
1164  4,
1165  1,
1166  14,
1167  3,
1168  25,
1169  5,
1170  6,
1171  3,
1172  18,
1173  1,
1174  29,
1175  5,
1176  9,
1177  3,
1178  22,
1179  4,
1180  2,
1181  3,
1182  13,
1183  2,
1184  23,
1185  6,
1186  4,
1187  3,
1188  15,
1189  2,
1190  27,
1191  4,
1192  7,
1193  3,
1194  20,
1195  4,
1196  1,
1197  2,
1198  11,
1199  3,
1200  21,
1201  6,
1202  3,
1203  2,
1204  15,
1205  1,
1206  25,
1207  6,
1208  6,
1209  2,
1210  17,
1211  3,
1212  29,
1213  4,
1214  10,
1215  2,
1216  20,
1217  6,
1218  3,
1219  1,
1220  13,
1221  3,
1222  24,
1223  5,
1224  4,
1225  3,
1226  17,
1227  1,
1228  28,
1229  5,
1230  8,
1231  3,
1232  18,
1233  6,
1234  1,
1235  1,
1236  12,
1237  2,
1238  22,
1239  6,
1240  2,
1241  3,
1242  14,
1243  2,
1244  26,
1245  4,
1246  6,
1247  3,
1248  17,
1249  2,
1250  28,
1251  6,
1252  10,
1253  1,
1254  20,
1255  6,
1256  1,
1257  2,
1258  12,
1259  3,
1260  24,
1261  4,
1262  5,
1263  2,
1264  15,
1265  3,
1266  28,
1267  4,
1268  9,
1269  2,
1270  19,
1271  6,
1272  33,
1273  3,
1274  12,
1275  1,
1276  23,
1277  5,
1278  3,
1279  3,
1280  13,
1281  3,
1282  25,
1283  4,
1284  6,
1285  2,
1286  16,
1287  3,
1288  26,
1289  6,
1290  8,
1291  2,
1292  20,
1293  4,
1294  30,
1295  3,
1296  11,
1297  2,
1298  24,
1299  4,
1300  4,
1301  3,
1302  15,
1303  2,
1304  25,
1305  6,
1306  8,
1307  1,
1308  18,
1309  6,
1310  33,
1311  2,
1312  9,
1313  3,
1314  22,
1315  4,
1316  3,
1317  2,
1318  13,
1319  3,
1320  25,
1321  4,
1322  6,
1323  3,
1324  17,
1325  2,
1326  27,
1327  6,
1328  9,
1329  1,
1330  21,
1331  5,
1332  1,
1333  3,
1334  11,
1335  3,
1336  23,
1337  4,
1338  5,
1339  2,
1340  15,
1341  3,
1342  25,
1343  6,
1344  6,
1345  2,
1346  19,
1347  4,
1348  33,
1349  3,
1350  10,
1351  2,
1352  22,
1353  4,
1354  3,
1355  3,
1356  14,
1357  2,
1358  24,
1359  6,
1360  6,
1361  1
1362  };
1363 
1364  private static readonly int[,] LunarMonthLen = new int[7, 14]
1365  {
1366  {
1367  0,
1368  0,
1369  0,
1370  0,
1371  0,
1372  0,
1373  0,
1374  0,
1375  0,
1376  0,
1377  0,
1378  0,
1379  0,
1380  0
1381  },
1382  {
1383  0,
1384  30,
1385  29,
1386  29,
1387  29,
1388  30,
1389  29,
1390  30,
1391  29,
1392  30,
1393  29,
1394  30,
1395  29,
1396  0
1397  },
1398  {
1399  0,
1400  30,
1401  29,
1402  30,
1403  29,
1404  30,
1405  29,
1406  30,
1407  29,
1408  30,
1409  29,
1410  30,
1411  29,
1412  0
1413  },
1414  {
1415  0,
1416  30,
1417  30,
1418  30,
1419  29,
1420  30,
1421  29,
1422  30,
1423  29,
1424  30,
1425  29,
1426  30,
1427  29,
1428  0
1429  },
1430  {
1431  0,
1432  30,
1433  29,
1434  29,
1435  29,
1436  30,
1437  30,
1438  29,
1439  30,
1440  29,
1441  30,
1442  29,
1443  30,
1444  29
1445  },
1446  {
1447  0,
1448  30,
1449  29,
1450  30,
1451  29,
1452  30,
1453  30,
1454  29,
1455  30,
1456  29,
1457  30,
1458  29,
1459  30,
1460  29
1461  },
1462  {
1463  0,
1464  30,
1465  30,
1466  30,
1467  29,
1468  30,
1469  30,
1470  29,
1471  30,
1472  29,
1473  30,
1474  29,
1475  30,
1476  29
1477  }
1478  };
1479 
1480  internal static readonly DateTime calendarMinValue = new DateTime(1583, 1, 1);
1481 
1482  internal static readonly DateTime calendarMaxValue = new DateTime(new DateTime(2239, 9, 29, 23, 59, 59, 999).Ticks + 9999);
1483 
1484  private const int DEFAULT_TWO_DIGIT_YEAR_MAX = 5790;
1485 
1488  public override DateTime MinSupportedDateTime => calendarMinValue;
1489 
1492  public override DateTime MaxSupportedDateTime => calendarMaxValue;
1493 
1496  public override CalendarAlgorithmType AlgorithmType => CalendarAlgorithmType.LunisolarCalendar;
1497 
1498  internal override int ID => 8;
1499 
1502  public override int[] Eras => new int[1]
1503  {
1504  HebrewEra
1505  };
1506 
1511  public override int TwoDigitYearMax
1512  {
1513  get
1514  {
1515  if (twoDigitYearMax == -1)
1516  {
1517  twoDigitYearMax = Calendar.GetSystemTwoDigitYearSetting(ID, 5790);
1518  }
1519  return twoDigitYearMax;
1520  }
1521  set
1522  {
1523  VerifyWritable();
1524  if (value != 99)
1525  {
1526  CheckHebrewYearValue(value, HebrewEra, "value");
1527  }
1528  twoDigitYearMax = value;
1529  }
1530  }
1531 
1532  private static void CheckHebrewYearValue(int y, int era, string varName)
1533  {
1534  CheckEraRange(era);
1535  if (y > 5999 || y < 5343)
1536  {
1537  throw new ArgumentOutOfRangeException(varName, string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 5343, 5999));
1538  }
1539  }
1540 
1541  private void CheckHebrewMonthValue(int year, int month, int era)
1542  {
1543  int monthsInYear = GetMonthsInYear(year, era);
1544  if (month < 1 || month > monthsInYear)
1545  {
1546  throw new ArgumentOutOfRangeException("month", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, monthsInYear));
1547  }
1548  }
1549 
1550  private void CheckHebrewDayValue(int year, int month, int day, int era)
1551  {
1552  int daysInMonth = GetDaysInMonth(year, month, era);
1553  if (day < 1 || day > daysInMonth)
1554  {
1555  throw new ArgumentOutOfRangeException("day", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, daysInMonth));
1556  }
1557  }
1558 
1559  internal static void CheckEraRange(int era)
1560  {
1561  if (era != 0 && era != HebrewEra)
1562  {
1563  throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue"));
1564  }
1565  }
1566 
1567  private static void CheckTicksRange(long ticks)
1568  {
1569  if (ticks < calendarMinValue.Ticks || ticks > calendarMaxValue.Ticks)
1570  {
1571  throw new ArgumentOutOfRangeException("time", string.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("ArgumentOutOfRange_CalendarRange"), calendarMinValue, calendarMaxValue));
1572  }
1573  }
1574 
1575  internal static int GetResult(__DateBuffer result, int part)
1576  {
1577  switch (part)
1578  {
1579  case 0:
1580  return result.year;
1581  case 2:
1582  return result.month;
1583  case 3:
1584  return result.day;
1585  default:
1586  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DateTimeParsing"));
1587  }
1588  }
1589 
1590  internal static int GetLunarMonthDay(int gregorianYear, __DateBuffer lunarDate)
1591  {
1592  int num = gregorianYear - 1583;
1593  if (num < 0 || num > 656)
1594  {
1595  throw new ArgumentOutOfRangeException("gregorianYear");
1596  }
1597  num *= 2;
1598  lunarDate.day = HebrewTable[num];
1599  int result = HebrewTable[num + 1];
1600  switch (lunarDate.day)
1601  {
1602  case 0:
1603  lunarDate.month = 5;
1604  lunarDate.day = 1;
1605  break;
1606  case 30:
1607  lunarDate.month = 3;
1608  break;
1609  case 31:
1610  lunarDate.month = 5;
1611  lunarDate.day = 2;
1612  break;
1613  case 32:
1614  lunarDate.month = 5;
1615  lunarDate.day = 3;
1616  break;
1617  case 33:
1618  lunarDate.month = 3;
1619  lunarDate.day = 29;
1620  break;
1621  default:
1622  lunarDate.month = 4;
1623  break;
1624  }
1625  return result;
1626  }
1627 
1628  internal virtual int GetDatePart(long ticks, int part)
1629  {
1630  CheckTicksRange(ticks);
1631  DateTime dateTime = new DateTime(ticks);
1632  int year = dateTime.Year;
1633  int month = dateTime.Month;
1634  int day = dateTime.Day;
1635  __DateBuffer _DateBuffer = new __DateBuffer();
1636  _DateBuffer.year = year + 3760;
1637  int num = GetLunarMonthDay(year, _DateBuffer);
1638  __DateBuffer _DateBuffer2 = new __DateBuffer();
1639  _DateBuffer2.year = _DateBuffer.year;
1640  _DateBuffer2.month = _DateBuffer.month;
1641  _DateBuffer2.day = _DateBuffer.day;
1642  long absoluteDate = GregorianCalendar.GetAbsoluteDate(year, month, day);
1643  if (month == 1 && day == 1)
1644  {
1645  return GetResult(_DateBuffer2, part);
1646  }
1647  long num2 = absoluteDate - GregorianCalendar.GetAbsoluteDate(year, 1, 1);
1648  if (num2 + _DateBuffer.day <= LunarMonthLen[num, _DateBuffer.month])
1649  {
1650  _DateBuffer2.day += (int)num2;
1651  return GetResult(_DateBuffer2, part);
1652  }
1653  _DateBuffer2.month++;
1654  _DateBuffer2.day = 1;
1655  num2 -= LunarMonthLen[num, _DateBuffer.month] - _DateBuffer.day;
1656  if (num2 > 1)
1657  {
1658  while (num2 > LunarMonthLen[num, _DateBuffer2.month])
1659  {
1660  num2 -= LunarMonthLen[num, _DateBuffer2.month++];
1661  if (_DateBuffer2.month > 13 || LunarMonthLen[num, _DateBuffer2.month] == 0)
1662  {
1663  _DateBuffer2.year++;
1664  num = HebrewTable[(year + 1 - 1583) * 2 + 1];
1665  _DateBuffer2.month = 1;
1666  }
1667  }
1668  _DateBuffer2.day += (int)(num2 - 1);
1669  }
1670  return GetResult(_DateBuffer2, part);
1671  }
1672 
1680  public override DateTime AddMonths(DateTime time, int months)
1681  {
1682  try
1683  {
1684  int num = GetDatePart(time.Ticks, 0);
1685  int datePart = GetDatePart(time.Ticks, 2);
1686  int num2 = GetDatePart(time.Ticks, 3);
1687  int num3;
1688  if (months >= 0)
1689  {
1690  int monthsInYear;
1691  for (num3 = datePart + months; num3 > (monthsInYear = GetMonthsInYear(num, 0)); num3 -= monthsInYear)
1692  {
1693  num++;
1694  }
1695  }
1696  else if ((num3 = datePart + months) <= 0)
1697  {
1698  months = -months;
1699  months -= datePart;
1700  num--;
1701  int monthsInYear;
1702  while (months > (monthsInYear = GetMonthsInYear(num, 0)))
1703  {
1704  num--;
1705  months -= monthsInYear;
1706  }
1707  monthsInYear = GetMonthsInYear(num, 0);
1708  num3 = monthsInYear - months;
1709  }
1710  int daysInMonth = GetDaysInMonth(num, num3);
1711  if (num2 > daysInMonth)
1712  {
1713  num2 = daysInMonth;
1714  }
1715  return new DateTime(ToDateTime(num, num3, num2, 0, 0, 0, 0).Ticks + time.Ticks % 864000000000L);
1716  }
1717  catch (ArgumentException)
1718  {
1719  throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_AddValue")));
1720  }
1721  }
1722 
1728  public override DateTime AddYears(DateTime time, int years)
1729  {
1730  int datePart = GetDatePart(time.Ticks, 0);
1731  int num = GetDatePart(time.Ticks, 2);
1732  int num2 = GetDatePart(time.Ticks, 3);
1733  datePart += years;
1734  CheckHebrewYearValue(datePart, 0, "years");
1735  int monthsInYear = GetMonthsInYear(datePart, 0);
1736  if (num > monthsInYear)
1737  {
1738  num = monthsInYear;
1739  }
1740  int daysInMonth = GetDaysInMonth(datePart, num);
1741  if (num2 > daysInMonth)
1742  {
1743  num2 = daysInMonth;
1744  }
1745  long ticks = ToDateTime(datePart, num, num2, 0, 0, 0, 0).Ticks + time.Ticks % 864000000000L;
1746  Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
1747  return new DateTime(ticks);
1748  }
1749 
1753  public override int GetDayOfMonth(DateTime time)
1754  {
1755  return GetDatePart(time.Ticks, 3);
1756  }
1757 
1761  public override DayOfWeek GetDayOfWeek(DateTime time)
1762  {
1763  return (DayOfWeek)((int)(time.Ticks / 864000000000L + 1) % 7);
1764  }
1765 
1766  internal static int GetHebrewYearType(int year, int era)
1767  {
1768  CheckHebrewYearValue(year, era, "year");
1769  return HebrewTable[(year - 3760 - 1583) * 2 + 1];
1770  }
1771 
1777  public override int GetDayOfYear(DateTime time)
1778  {
1779  int year = GetYear(time);
1780  DateTime dateTime = (year != 5343) ? ToDateTime(year, 1, 1, 0, 0, 0, 0, 0) : new DateTime(1582, 9, 27);
1781  return (int)((time.Ticks - dateTime.Ticks) / 864000000000L) + 1;
1782  }
1783 
1791  public override int GetDaysInMonth(int year, int month, int era)
1792  {
1793  CheckEraRange(era);
1794  int hebrewYearType = GetHebrewYearType(year, era);
1795  CheckHebrewMonthValue(year, month, era);
1796  int num = LunarMonthLen[hebrewYearType, month];
1797  if (num == 0)
1798  {
1799  throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month"));
1800  }
1801  return num;
1802  }
1803 
1810  public override int GetDaysInYear(int year, int era)
1811  {
1812  CheckEraRange(era);
1813  int hebrewYearType = GetHebrewYearType(year, era);
1814  if (hebrewYearType < 4)
1815  {
1816  return 352 + hebrewYearType;
1817  }
1818  return 382 + (hebrewYearType - 3);
1819  }
1820 
1824  public override int GetEra(DateTime time)
1825  {
1826  return HebrewEra;
1827  }
1828 
1834  public override int GetMonth(DateTime time)
1835  {
1836  return GetDatePart(time.Ticks, 2);
1837  }
1838 
1845  public override int GetMonthsInYear(int year, int era)
1846  {
1847  if (!IsLeapYear(year, era))
1848  {
1849  return 12;
1850  }
1851  return 13;
1852  }
1853 
1859  public override int GetYear(DateTime time)
1860  {
1861  return GetDatePart(time.Ticks, 0);
1862  }
1863 
1873  public override bool IsLeapDay(int year, int month, int day, int era)
1874  {
1875  if (IsLeapMonth(year, month, era))
1876  {
1877  CheckHebrewDayValue(year, month, day, era);
1878  return true;
1879  }
1880  if (IsLeapYear(year, 0) && month == 6 && day == 30)
1881  {
1882  return true;
1883  }
1884  CheckHebrewDayValue(year, month, day, era);
1885  return false;
1886  }
1887 
1895  public override int GetLeapMonth(int year, int era)
1896  {
1897  if (IsLeapYear(year, era))
1898  {
1899  return 7;
1900  }
1901  return 0;
1902  }
1903 
1912  public override bool IsLeapMonth(int year, int month, int era)
1913  {
1914  bool flag = IsLeapYear(year, era);
1915  CheckHebrewMonthValue(year, month, era);
1916  if (flag && month == 7)
1917  {
1918  return true;
1919  }
1920  return false;
1921  }
1922 
1930  public override bool IsLeapYear(int year, int era)
1931  {
1932  CheckHebrewYearValue(year, era, "year");
1933  return (7L * (long)year + 1) % 19 < 7;
1934  }
1935 
1936  private static int GetDayDifference(int lunarYearType, int month1, int day1, int month2, int day2)
1937  {
1938  if (month1 == month2)
1939  {
1940  return day1 - day2;
1941  }
1942  bool flag = month1 > month2;
1943  if (flag)
1944  {
1945  int num = month1;
1946  int num2 = day1;
1947  month1 = month2;
1948  day1 = day2;
1949  month2 = num;
1950  day2 = num2;
1951  }
1952  int num3 = LunarMonthLen[lunarYearType, month1] - day1;
1953  month1++;
1954  while (month1 < month2)
1955  {
1956  num3 += LunarMonthLen[lunarYearType, month1++];
1957  }
1958  num3 += day2;
1959  if (!flag)
1960  {
1961  return -num3;
1962  }
1963  return num3;
1964  }
1965 
1966  private static DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond)
1967  {
1968  int num = hebrewYear - 3760;
1969  __DateBuffer _DateBuffer = new __DateBuffer();
1970  int lunarMonthDay = GetLunarMonthDay(num, _DateBuffer);
1971  if (hebrewMonth == _DateBuffer.month && hebrewDay == _DateBuffer.day)
1972  {
1973  return new DateTime(num, 1, 1, hour, minute, second, millisecond);
1974  }
1975  int dayDifference = GetDayDifference(lunarMonthDay, hebrewMonth, hebrewDay, _DateBuffer.month, _DateBuffer.day);
1976  return new DateTime(new DateTime(num, 1, 1).Ticks + dayDifference * 864000000000L + Calendar.TimeToTicks(hour, minute, second, millisecond));
1977  }
1978 
1995  public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
1996  {
1997  CheckHebrewYearValue(year, era, "year");
1998  CheckHebrewMonthValue(year, month, era);
1999  CheckHebrewDayValue(year, month, day, era);
2000  DateTime result = HebrewToGregorian(year, month, day, hour, minute, second, millisecond);
2001  CheckTicksRange(result.Ticks);
2002  return result;
2003  }
2004 
2011  public override int ToFourDigitYear(int year)
2012  {
2013  if (year < 0)
2014  {
2015  throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
2016  }
2017  if (year < 100)
2018  {
2019  return base.ToFourDigitYear(year);
2020  }
2021  if (year > 5999 || year < 5343)
2022  {
2023  throw new ArgumentOutOfRangeException("year", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 5343, 5999));
2024  }
2025  return year;
2026  }
2027  }
2028 }
override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
Returns a T:System.DateTime that is set to the specified date and time in the specified era.
override CalendarAlgorithmType AlgorithmType
Gets a value that indicates whether the current calendar is solar-based, lunar-based,...
override bool IsLeapMonth(int year, int month, int era)
Determines whether the specified month in the specified year in the specified era is a leap month.
Represents time in divisions, such as weeks, months, and years.
Definition: Calendar.cs:11
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week in the specified T:System.DateTime.
override int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime.
override DateTime AddMonths(DateTime time, int months)
Returns a T:System.DateTime that is the specified number of months away from the specified T:System....
override int GetMonthsInYear(int year, int era)
Returns the number of months in the specified year in the specified era.
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime.
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override int GetDayOfMonth(DateTime time)
Returns the day of the month in the specified T:System.DateTime.
static readonly int HebrewEra
Represents the current era. This field is constant.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
Calendar()
Initializes a new instance of the T:System.Globalization.Calendar class.
Definition: Calendar.cs:201
override bool IsLeapDay(int year, int month, int day, int era)
Determines whether the specified date in the specified era is a leap day.
A type representing a date and time value.
override int [] Eras
Gets the list of eras in the T:System.Globalization.HebrewCalendar.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by the T:System.Globalization.HebrewCalendar type.
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime.
Format character that affects the layout of text or the operation of text processes,...
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year in the specified era.
override int GetDaysInMonth(int year, int month, int era)
Returns the number of days in the specified month in the specified year in the specified era.
override DateTime MinSupportedDateTime
Gets the earliest date and time supported by the T:System.Globalization.HebrewCalendar type.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
The exception that is thrown when one of the arguments provided to a method is not valid.
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime value.
CalendarAlgorithmType
Specifies whether a calendar is solar-based, lunar-based, or lunisolar-based.
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap year.
Specifies that the class can be serialized.
override DateTime AddYears(DateTime time, int years)
Returns a T:System.DateTime that is the specified number of years away from the specified T:System....
Represents the Hebrew calendar.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
DayOfWeek
Specifies the day of the week.
Definition: DayOfWeek.cs:9
override int ToFourDigitYear(int year)
Converts the specified year to a 4-digit year by using the P:System.Globalization....
long Ticks
Gets the number of ticks that represent the date and time of this instance.
Definition: DateTime.cs:315
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.