开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

gwdcode/JDK11.0.2-lib.src.java.base.java

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
jdk11.0.2lib.src.java.base.java
/
util
/
SimpleTimeZone.java
jdk11.0.2lib.src.java.base.java
/
util
/
SimpleTimeZone.java
SimpleTimeZone.java 69.26 KB
一键复制 编辑 原始数据 按行查看 历史
gwdcode 提交于 2020年10月30日 22:13 +08:00 . 常用普通java包(jdk11.0.2)
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 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
/*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/*
* (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
* (C) Copyright IBM Corp. 1996 - All Rights Reserved
*
* The original version of this source code and documentation is copyrighted
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
* materials are provided under terms of a License Agreement between Taligent
* and Sun. This technology is protected by multiple US and International
* patents. This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
*/
package java.util;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.io.InvalidObjectException;
import sun.util.calendar.CalendarSystem;
import sun.util.calendar.CalendarUtils;
import sun.util.calendar.BaseCalendar;
import sun.util.calendar.Gregorian;
/**
* <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
* that represents a time zone for use with a Gregorian calendar.
* The class holds an offset from GMT, called <em>raw offset</em>, and start
* and end rules for a daylight saving time schedule. Since it only holds
* single values for each, it cannot handle historical changes in the offset
* from GMT and the daylight saving schedule, except that the {@link
* #setStartYear setStartYear} method can specify the year when the daylight
* saving time schedule starts in effect.
* <p>
* To construct a <code>SimpleTimeZone</code> with a daylight saving time
* schedule, the schedule can be described with a set of rules,
* <em>start-rule</em> and <em>end-rule</em>. A day when daylight saving time
* starts or ends is specified by a combination of <em>month</em>,
* <em>day-of-month</em>, and <em>day-of-week</em> values. The <em>month</em>
* value is represented by a Calendar {@link Calendar#MONTH MONTH} field
* value, such as {@link Calendar#MARCH}. The <em>day-of-week</em> value is
* represented by a Calendar {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value,
* such as {@link Calendar#SUNDAY SUNDAY}. The meanings of value combinations
* are as follows.
*
* <ul>
* <li><b>Exact day of month</b><br>
* To specify an exact day of month, set the <em>month</em> and
* <em>day-of-month</em> to an exact value, and <em>day-of-week</em> to zero. For
* example, to specify March 1, set the <em>month</em> to {@link Calendar#MARCH
* MARCH}, <em>day-of-month</em> to 1, and <em>day-of-week</em> to 0.</li>
*
* <li><b>Day of week on or after day of month</b><br>
* To specify a day of week on or after an exact day of month, set the
* <em>month</em> to an exact month value, <em>day-of-month</em> to the day on
* or after which the rule is applied, and <em>day-of-week</em> to a negative {@link
* Calendar#DAY_OF_WEEK DAY_OF_WEEK} field value. For example, to specify the
* second Sunday of April, set <em>month</em> to {@link Calendar#APRIL APRIL},
* <em>day-of-month</em> to 8, and <em>day-of-week</em> to <code>-</code>{@link
* Calendar#SUNDAY SUNDAY}.</li>
*
* <li><b>Day of week on or before day of month</b><br>
* To specify a day of the week on or before an exact day of the month, set
* <em>day-of-month</em> and <em>day-of-week</em> to a negative value. For
* example, to specify the last Wednesday on or before the 21st of March, set
* <em>month</em> to {@link Calendar#MARCH MARCH}, <em>day-of-month</em> is -21
* and <em>day-of-week</em> is <code>-</code>{@link Calendar#WEDNESDAY WEDNESDAY}. </li>
*
* <li><b>Last day-of-week of month</b><br>
* To specify, the last day-of-week of the month, set <em>day-of-week</em> to a
* {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} value and <em>day-of-month</em> to
* -1. For example, to specify the last Sunday of October, set <em>month</em>
* to {@link Calendar#OCTOBER OCTOBER}, <em>day-of-week</em> to {@link
* Calendar#SUNDAY SUNDAY} and <em>day-of-month</em> to -1. </li>
*
* </ul>
* The time of the day at which daylight saving time starts or ends is
* specified by a millisecond value within the day. There are three kinds of
* <em>mode</em>s to specify the time: {@link #WALL_TIME}, {@link
* #STANDARD_TIME} and {@link #UTC_TIME}. For example, if daylight
* saving time ends
* at 2:00 am in the wall clock time, it can be specified by 7200000
* milliseconds in the {@link #WALL_TIME} mode. In this case, the wall clock time
* for an <em>end-rule</em> means the same thing as the daylight time.
* <p>
* The following are examples of parameters for constructing time zone objects.
* <pre><code>
* // Base GMT offset: -8:00
* // DST starts: at 2:00am in standard time
* // on the first Sunday in April
* // DST ends: at 2:00am in daylight time
* // on the last Sunday in October
* // Save: 1 hour
* SimpleTimeZone(-28800000,
* "America/Los_Angeles",
* Calendar.APRIL, 1, -Calendar.SUNDAY,
* 7200000,
* Calendar.OCTOBER, -1, Calendar.SUNDAY,
* 7200000,
* 3600000)
*
* // Base GMT offset: +1:00
* // DST starts: at 1:00am in UTC time
* // on the last Sunday in March
* // DST ends: at 1:00am in UTC time
* // on the last Sunday in October
* // Save: 1 hour
* SimpleTimeZone(3600000,
* "Europe/Paris",
* Calendar.MARCH, -1, Calendar.SUNDAY,
* 3600000, SimpleTimeZone.UTC_TIME,
* Calendar.OCTOBER, -1, Calendar.SUNDAY,
* 3600000, SimpleTimeZone.UTC_TIME,
* 3600000)
* </code></pre>
* These parameter rules are also applicable to the set rule methods, such as
* <code>setStartRule</code>.
*
* @since 1.1
* @see Calendar
* @see GregorianCalendar
* @see TimeZone
* @author David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
*/
public class SimpleTimeZone extends TimeZone {
/**
* Constructs a SimpleTimeZone with the given base time zone offset from GMT
* and time zone ID with no daylight saving time schedule.
*
* @param rawOffset The base time zone offset in milliseconds to GMT.
* @param ID The time zone name that is given to this instance.
*/
public SimpleTimeZone(int rawOffset, String ID)
{
this.rawOffset = rawOffset;
setID (ID);
dstSavings = millisPerHour; // In case user sets rules later
}
/**
* Constructs a SimpleTimeZone with the given base time zone offset from
* GMT, time zone ID, and rules for starting and ending the daylight
* time.
* Both <code>startTime</code> and <code>endTime</code> are specified to be
* represented in the wall clock time. The amount of daylight saving is
* assumed to be 3600000 milliseconds (i.e., one hour). This constructor is
* equivalent to:
* <pre><code>
* SimpleTimeZone(rawOffset,
* ID,
* startMonth,
* startDay,
* startDayOfWeek,
* startTime,
* SimpleTimeZone.{@link #WALL_TIME},
* endMonth,
* endDay,
* endDayOfWeek,
* endTime,
* SimpleTimeZone.{@link #WALL_TIME},
* 3600000)
* </code></pre>
*
* @param rawOffset The given base time zone offset from GMT.
* @param ID The time zone ID which is given to this object.
* @param startMonth The daylight saving time starting month. Month is
* a {@link Calendar#MONTH MONTH} field value (0-based. e.g., 0
* for January).
* @param startDay The day of the month on which the daylight saving time starts.
* See the class description for the special cases of this parameter.
* @param startDayOfWeek The daylight saving time starting day-of-week.
* See the class description for the special cases of this parameter.
* @param startTime The daylight saving time starting time in local wall clock
* time (in milliseconds within the day), which is local
* standard time in this case.
* @param endMonth The daylight saving time ending month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 9 for October).
* @param endDay The day of the month on which the daylight saving time ends.
* See the class description for the special cases of this parameter.
* @param endDayOfWeek The daylight saving time ending day-of-week.
* See the class description for the special cases of this parameter.
* @param endTime The daylight saving ending time in local wall clock time,
* (in milliseconds within the day) which is local daylight
* time in this case.
* @exception IllegalArgumentException if the month, day, dayOfWeek, or time
* parameters are out of range for the start or end rule
*/
public SimpleTimeZone(int rawOffset, String ID,
int startMonth, int startDay, int startDayOfWeek, int startTime,
int endMonth, int endDay, int endDayOfWeek, int endTime)
{
this(rawOffset, ID,
startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
millisPerHour);
}
/**
* Constructs a SimpleTimeZone with the given base time zone offset from
* GMT, time zone ID, and rules for starting and ending the daylight
* time.
* Both <code>startTime</code> and <code>endTime</code> are assumed to be
* represented in the wall clock time. This constructor is equivalent to:
* <pre><code>
* SimpleTimeZone(rawOffset,
* ID,
* startMonth,
* startDay,
* startDayOfWeek,
* startTime,
* SimpleTimeZone.{@link #WALL_TIME},
* endMonth,
* endDay,
* endDayOfWeek,
* endTime,
* SimpleTimeZone.{@link #WALL_TIME},
* dstSavings)
* </code></pre>
*
* @param rawOffset The given base time zone offset from GMT.
* @param ID The time zone ID which is given to this object.
* @param startMonth The daylight saving time starting month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 0 for January).
* @param startDay The day of the month on which the daylight saving time starts.
* See the class description for the special cases of this parameter.
* @param startDayOfWeek The daylight saving time starting day-of-week.
* See the class description for the special cases of this parameter.
* @param startTime The daylight saving time starting time in local wall clock
* time, which is local standard time in this case.
* @param endMonth The daylight saving time ending month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 9 for October).
* @param endDay The day of the month on which the daylight saving time ends.
* See the class description for the special cases of this parameter.
* @param endDayOfWeek The daylight saving time ending day-of-week.
* See the class description for the special cases of this parameter.
* @param endTime The daylight saving ending time in local wall clock time,
* which is local daylight time in this case.
* @param dstSavings The amount of time in milliseconds saved during
* daylight saving time.
* @exception IllegalArgumentException if the month, day, dayOfWeek, or time
* parameters are out of range for the start or end rule
* @since 1.2
*/
public SimpleTimeZone(int rawOffset, String ID,
int startMonth, int startDay, int startDayOfWeek, int startTime,
int endMonth, int endDay, int endDayOfWeek, int endTime,
int dstSavings)
{
this(rawOffset, ID,
startMonth, startDay, startDayOfWeek, startTime, WALL_TIME,
endMonth, endDay, endDayOfWeek, endTime, WALL_TIME,
dstSavings);
}
/**
* Constructs a SimpleTimeZone with the given base time zone offset from
* GMT, time zone ID, and rules for starting and ending the daylight
* time.
* This constructor takes the full set of the start and end rules
* parameters, including modes of <code>startTime</code> and
* <code>endTime</code>. The mode specifies either {@link #WALL_TIME wall
* time} or {@link #STANDARD_TIME standard time} or {@link #UTC_TIME UTC
* time}.
*
* @param rawOffset The given base time zone offset from GMT.
* @param ID The time zone ID which is given to this object.
* @param startMonth The daylight saving time starting month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 0 for January).
* @param startDay The day of the month on which the daylight saving time starts.
* See the class description for the special cases of this parameter.
* @param startDayOfWeek The daylight saving time starting day-of-week.
* See the class description for the special cases of this parameter.
* @param startTime The daylight saving time starting time in the time mode
* specified by <code>startTimeMode</code>.
* @param startTimeMode The mode of the start time specified by startTime.
* @param endMonth The daylight saving time ending month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 9 for October).
* @param endDay The day of the month on which the daylight saving time ends.
* See the class description for the special cases of this parameter.
* @param endDayOfWeek The daylight saving time ending day-of-week.
* See the class description for the special cases of this parameter.
* @param endTime The daylight saving ending time in time time mode
* specified by <code>endTimeMode</code>.
* @param endTimeMode The mode of the end time specified by endTime
* @param dstSavings The amount of time in milliseconds saved during
* daylight saving time.
*
* @exception IllegalArgumentException if the month, day, dayOfWeek, time more, or
* time parameters are out of range for the start or end rule, or if a time mode
* value is invalid.
*
* @see #WALL_TIME
* @see #STANDARD_TIME
* @see #UTC_TIME
*
* @since 1.4
*/
public SimpleTimeZone(int rawOffset, String ID,
int startMonth, int startDay, int startDayOfWeek,
int startTime, int startTimeMode,
int endMonth, int endDay, int endDayOfWeek,
int endTime, int endTimeMode,
int dstSavings) {
setID(ID);
this.rawOffset = rawOffset;
this.startMonth = startMonth;
this.startDay = startDay;
this.startDayOfWeek = startDayOfWeek;
this.startTime = startTime;
this.startTimeMode = startTimeMode;
this.endMonth = endMonth;
this.endDay = endDay;
this.endDayOfWeek = endDayOfWeek;
this.endTime = endTime;
this.endTimeMode = endTimeMode;
this.dstSavings = dstSavings;
// this.useDaylight is set by decodeRules
decodeRules();
if (dstSavings <= 0) {
throw new IllegalArgumentException("Illegal daylight saving value: " + dstSavings);
}
}
/**
* Sets the daylight saving time starting year.
*
* @param year The daylight saving starting year.
*/
public void setStartYear(int year)
{
startYear = year;
invalidateCache();
}
/**
* Sets the daylight saving time start rule. For example, if daylight saving
* time starts on the first Sunday in April at 2 am in local wall clock
* time, you can set the start rule by calling:
* <pre><code>setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);</code></pre>
*
* @param startMonth The daylight saving time starting month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 0 for January).
* @param startDay The day of the month on which the daylight saving time starts.
* See the class description for the special cases of this parameter.
* @param startDayOfWeek The daylight saving time starting day-of-week.
* See the class description for the special cases of this parameter.
* @param startTime The daylight saving time starting time in local wall clock
* time, which is local standard time in this case.
* @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>,
* <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range
*/
public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime)
{
this.startMonth = startMonth;
this.startDay = startDay;
this.startDayOfWeek = startDayOfWeek;
this.startTime = startTime;
startTimeMode = WALL_TIME;
decodeStartRule();
invalidateCache();
}
/**
* Sets the daylight saving time start rule to a fixed date within a month.
* This method is equivalent to:
* <pre><code>setStartRule(startMonth, startDay, 0, startTime)</code></pre>
*
* @param startMonth The daylight saving time starting month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 0 for January).
* @param startDay The day of the month on which the daylight saving time starts.
* @param startTime The daylight saving time starting time in local wall clock
* time, which is local standard time in this case.
* See the class description for the special cases of this parameter.
* @exception IllegalArgumentException if the <code>startMonth</code>,
* <code>startDayOfMonth</code>, or <code>startTime</code> parameters are out of range
* @since 1.2
*/
public void setStartRule(int startMonth, int startDay, int startTime) {
setStartRule(startMonth, startDay, 0, startTime);
}
/**
* Sets the daylight saving time start rule to a weekday before or after the given date within
* a month, e.g., the first Monday on or after the 8th.
*
* @param startMonth The daylight saving time starting month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 0 for January).
* @param startDay The day of the month on which the daylight saving time starts.
* @param startDayOfWeek The daylight saving time starting day-of-week.
* @param startTime The daylight saving time starting time in local wall clock
* time, which is local standard time in this case.
* @param after If true, this rule selects the first <code>dayOfWeek</code> on or
* <em>after</em> <code>dayOfMonth</code>. If false, this rule
* selects the last <code>dayOfWeek</code> on or <em>before</em>
* <code>dayOfMonth</code>.
* @exception IllegalArgumentException if the <code>startMonth</code>, <code>startDay</code>,
* <code>startDayOfWeek</code>, or <code>startTime</code> parameters are out of range
* @since 1.2
*/
public void setStartRule(int startMonth, int startDay, int startDayOfWeek,
int startTime, boolean after)
{
// TODO: this method doesn't check the initial values of dayOfMonth or dayOfWeek.
if (after) {
setStartRule(startMonth, startDay, -startDayOfWeek, startTime);
} else {
setStartRule(startMonth, -startDay, -startDayOfWeek, startTime);
}
}
/**
* Sets the daylight saving time end rule. For example, if daylight saving time
* ends on the last Sunday in October at 2 am in wall clock time,
* you can set the end rule by calling:
* <code>setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);</code>
*
* @param endMonth The daylight saving time ending month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 9 for October).
* @param endDay The day of the month on which the daylight saving time ends.
* See the class description for the special cases of this parameter.
* @param endDayOfWeek The daylight saving time ending day-of-week.
* See the class description for the special cases of this parameter.
* @param endTime The daylight saving ending time in local wall clock time,
* (in milliseconds within the day) which is local daylight
* time in this case.
* @exception IllegalArgumentException if the <code>endMonth</code>, <code>endDay</code>,
* <code>endDayOfWeek</code>, or <code>endTime</code> parameters are out of range
*/
public void setEndRule(int endMonth, int endDay, int endDayOfWeek,
int endTime)
{
this.endMonth = endMonth;
this.endDay = endDay;
this.endDayOfWeek = endDayOfWeek;
this.endTime = endTime;
this.endTimeMode = WALL_TIME;
decodeEndRule();
invalidateCache();
}
/**
* Sets the daylight saving time end rule to a fixed date within a month.
* This method is equivalent to:
* <pre><code>setEndRule(endMonth, endDay, 0, endTime)</code></pre>
*
* @param endMonth The daylight saving time ending month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 9 for October).
* @param endDay The day of the month on which the daylight saving time ends.
* @param endTime The daylight saving ending time in local wall clock time,
* (in milliseconds within the day) which is local daylight
* time in this case.
* @exception IllegalArgumentException the <code>endMonth</code>, <code>endDay</code>,
* or <code>endTime</code> parameters are out of range
* @since 1.2
*/
public void setEndRule(int endMonth, int endDay, int endTime)
{
setEndRule(endMonth, endDay, 0, endTime);
}
/**
* Sets the daylight saving time end rule to a weekday before or after the given date within
* a month, e.g., the first Monday on or after the 8th.
*
* @param endMonth The daylight saving time ending month. Month is
* a {@link Calendar#MONTH MONTH} field
* value (0-based. e.g., 9 for October).
* @param endDay The day of the month on which the daylight saving time ends.
* @param endDayOfWeek The daylight saving time ending day-of-week.
* @param endTime The daylight saving ending time in local wall clock time,
* (in milliseconds within the day) which is local daylight
* time in this case.
* @param after If true, this rule selects the first <code>endDayOfWeek</code> on
* or <em>after</em> <code>endDay</code>. If false, this rule
* selects the last <code>endDayOfWeek</code> on or before
* <code>endDay</code> of the month.
* @exception IllegalArgumentException the <code>endMonth</code>, <code>endDay</code>,
* <code>endDayOfWeek</code>, or <code>endTime</code> parameters are out of range
* @since 1.2
*/
public void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after)
{
if (after) {
setEndRule(endMonth, endDay, -endDayOfWeek, endTime);
} else {
setEndRule(endMonth, -endDay, -endDayOfWeek, endTime);
}
}
/**
* Returns the offset of this time zone from UTC at the given
* time. If daylight saving time is in effect at the given time,
* the offset value is adjusted with the amount of daylight
* saving.
*
* @param date the time at which the time zone offset is found
* @return the amount of time in milliseconds to add to UTC to get
* local time.
* @since 1.4
*/
public int getOffset(long date) {
return getOffsets(date, null);
}
/**
* @see TimeZone#getOffsets
*/
int getOffsets(long date, int[] offsets) {
int offset = rawOffset;
computeOffset:
if (useDaylight) {
Cache cache = this.cache;
if (cache != null) {
if (date >= cache.start && date < cache.end) {
offset += dstSavings;
break computeOffset;
}
}
BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
gcal : (BaseCalendar) CalendarSystem.forName("julian");
BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
// Get the year in local time
cal.getCalendarDate(date + rawOffset, cdate);
int year = cdate.getNormalizedYear();
if (year >= startYear) {
// Clear time elements for the transition calculations
cdate.setTimeOfDay(0, 0, 0, 0);
offset = getOffset(cal, cdate, year, date);
}
}
if (offsets != null) {
offsets[0] = rawOffset;
offsets[1] = offset - rawOffset;
}
return offset;
}
/**
* Returns the difference in milliseconds between local time and
* UTC, taking into account both the raw offset and the effect of
* daylight saving, for the specified date and time. This method
* assumes that the start and end month are distinct. It also
* uses a default {@link GregorianCalendar} object as its
* underlying calendar, such as for determining leap years. Do
* not use the result of this method with a calendar other than a
* default <code>GregorianCalendar</code>.
*
* <p><em>Note: In general, clients should use
* <code>Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)</code>
* instead of calling this method.</em>
*
* @param era The era of the given date.
* @param year The year in the given date.
* @param month The month in the given date. Month is 0-based. e.g.,
* 0 for January.
* @param day The day-in-month of the given date.
* @param dayOfWeek The day-of-week of the given date.
* @param millis The milliseconds in day in <em>standard</em> local time.
* @return The milliseconds to add to UTC to get local time.
* @exception IllegalArgumentException the <code>era</code>,
* <code>month</code>, <code>day</code>, <code>dayOfWeek</code>,
* or <code>millis</code> parameters are out of range
*/
public int getOffset(int era, int year, int month, int day, int dayOfWeek,
int millis)
{
if (era != GregorianCalendar.AD && era != GregorianCalendar.BC) {
throw new IllegalArgumentException("Illegal era " + era);
}
int y = year;
if (era == GregorianCalendar.BC) {
// adjust y with the GregorianCalendar-style year numbering.
y = 1 - y;
}
// If the year isn't representable with the 64-bit long
// integer in milliseconds, convert the year to an
// equivalent year. This is required to pass some JCK test cases
// which are actually useless though because the specified years
// can't be supported by the Java time system.
if (y >= 292278994) {
y = 2800 + y % 2800;
} else if (y <= -292269054) {
// y %= 28 also produces an equivalent year, but positive
// year numbers would be convenient to use the UNIX cal
// command.
y = (int) CalendarUtils.mod((long) y, 28);
}
// convert year to its 1-based month value
int m = month + 1;
// First, calculate time as a Gregorian date.
BaseCalendar cal = gcal;
BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
cdate.setDate(y, m, day);
long time = cal.getTime(cdate); // normalize cdate
time += millis - rawOffset; // UTC time
// If the time value represents a time before the default
// Gregorian cutover, recalculate time using the Julian
// calendar system. For the Julian calendar system, the
// normalized year numbering is ..., -2 (BCE 2), -1 (BCE 1),
// 1, 2 ... which is different from the GregorianCalendar
// style year numbering (..., -1, 0 (BCE 1), 1, 2, ...).
if (time < GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER) {
cal = (BaseCalendar) CalendarSystem.forName("julian");
cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
cdate.setNormalizedDate(y, m, day);
time = cal.getTime(cdate) + millis - rawOffset;
}
if ((cdate.getNormalizedYear() != y)
|| (cdate.getMonth() != m)
|| (cdate.getDayOfMonth() != day)
// The validation should be cdate.getDayOfWeek() ==
// dayOfWeek. However, we don't check dayOfWeek for
// compatibility.
|| (dayOfWeek < Calendar.SUNDAY || dayOfWeek > Calendar.SATURDAY)
|| (millis < 0 || millis >= (24*60*60*1000))) {
throw new IllegalArgumentException();
}
if (!useDaylight || year < startYear || era != GregorianCalendar.CE) {
return rawOffset;
}
return getOffset(cal, cdate, y, time);
}
private int getOffset(BaseCalendar cal, BaseCalendar.Date cdate, int year, long time) {
Cache cache = this.cache;
if (cache != null) {
if (time >= cache.start && time < cache.end) {
return rawOffset + dstSavings;
}
if (year == cache.year) {
return rawOffset;
}
}
long start = getStart(cal, cdate, year);
long end = getEnd(cal, cdate, year);
int offset = rawOffset;
if (start <= end) {
if (time >= start && time < end) {
offset += dstSavings;
}
this.cache = new Cache(year, start, end);
} else {
if (time < end) {
// TODO: support Gregorian cutover. The previous year
// may be in the other calendar system.
start = getStart(cal, cdate, year - 1);
if (time >= start) {
offset += dstSavings;
}
} else if (time >= start) {
// TODO: support Gregorian cutover. The next year
// may be in the other calendar system.
end = getEnd(cal, cdate, year + 1);
if (time < end) {
offset += dstSavings;
}
}
if (start <= end) {
this.cache = new Cache((long) startYear - 1, start, end);
}
}
return offset;
}
private long getStart(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
int time = startTime;
if (startTimeMode != UTC_TIME) {
time -= rawOffset;
}
return getTransition(cal, cdate, startMode, year, startMonth, startDay,
startDayOfWeek, time);
}
private long getEnd(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
int time = endTime;
if (endTimeMode != UTC_TIME) {
time -= rawOffset;
}
if (endTimeMode == WALL_TIME) {
time -= dstSavings;
}
return getTransition(cal, cdate, endMode, year, endMonth, endDay,
endDayOfWeek, time);
}
private long getTransition(BaseCalendar cal, BaseCalendar.Date cdate,
int mode, int year, int month, int dayOfMonth,
int dayOfWeek, int timeOfDay) {
cdate.setNormalizedYear(year);
cdate.setMonth(month + 1);
switch (mode) {
case DOM_MODE:
cdate.setDayOfMonth(dayOfMonth);
break;
case DOW_IN_MONTH_MODE:
cdate.setDayOfMonth(1);
if (dayOfMonth < 0) {
cdate.setDayOfMonth(cal.getMonthLength(cdate));
}
cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate);
break;
case DOW_GE_DOM_MODE:
cdate.setDayOfMonth(dayOfMonth);
cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(1, dayOfWeek, cdate);
break;
case DOW_LE_DOM_MODE:
cdate.setDayOfMonth(dayOfMonth);
cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(-1, dayOfWeek, cdate);
break;
}
return cal.getTime(cdate) + timeOfDay;
}
/**
* Gets the GMT offset for this time zone.
* @return the GMT offset value in milliseconds
* @see #setRawOffset
*/
public int getRawOffset()
{
// The given date will be taken into account while
// we have the historical time zone data in place.
return rawOffset;
}
/**
* Sets the base time zone offset to GMT.
* This is the offset to add to UTC to get local time.
* @see #getRawOffset
*/
public void setRawOffset(int offsetMillis)
{
this.rawOffset = offsetMillis;
}
/**
* Sets the amount of time in milliseconds that the clock is advanced
* during daylight saving time.
* @param millisSavedDuringDST the number of milliseconds the time is
* advanced with respect to standard time when the daylight saving time rules
* are in effect. A positive number, typically one hour (3600000).
* @see #getDSTSavings
* @since 1.2
*/
public void setDSTSavings(int millisSavedDuringDST) {
if (millisSavedDuringDST <= 0) {
throw new IllegalArgumentException("Illegal daylight saving value: "
+ millisSavedDuringDST);
}
dstSavings = millisSavedDuringDST;
}
/**
* Returns the amount of time in milliseconds that the clock is
* advanced during daylight saving time.
*
* @return the number of milliseconds the time is advanced with
* respect to standard time when the daylight saving rules are in
* effect, or 0 (zero) if this time zone doesn't observe daylight
* saving time.
*
* @see #setDSTSavings
* @since 1.2
*/
public int getDSTSavings() {
return useDaylight ? dstSavings : 0;
}
/**
* Queries if this time zone uses daylight saving time.
* @return true if this time zone uses daylight saving time;
* false otherwise.
*/
public boolean useDaylightTime()
{
return useDaylight;
}
/**
* Returns {@code true} if this {@code SimpleTimeZone} observes
* Daylight Saving Time. This method is equivalent to {@link
* #useDaylightTime()}.
*
* @return {@code true} if this {@code SimpleTimeZone} observes
* Daylight Saving Time; {@code false} otherwise.
* @since 1.7
*/
@Override
public boolean observesDaylightTime() {
return useDaylightTime();
}
/**
* Queries if the given date is in daylight saving time.
* @return true if daylight saving time is in effective at the
* given date; false otherwise.
*/
public boolean inDaylightTime(Date date)
{
return (getOffset(date.getTime()) != rawOffset);
}
/**
* Returns a clone of this <code>SimpleTimeZone</code> instance.
* @return a clone of this instance.
*/
public Object clone()
{
return super.clone();
}
/**
* Generates the hash code for the SimpleDateFormat object.
* @return the hash code for this object
*/
public int hashCode()
{
return startMonth ^ startDay ^ startDayOfWeek ^ startTime ^
endMonth ^ endDay ^ endDayOfWeek ^ endTime ^ rawOffset;
}
/**
* Compares the equality of two <code>SimpleTimeZone</code> objects.
*
* @param obj The <code>SimpleTimeZone</code> object to be compared with.
* @return True if the given <code>obj</code> is the same as this
* <code>SimpleTimeZone</code> object; false otherwise.
*/
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (!(obj instanceof SimpleTimeZone)) {
return false;
}
SimpleTimeZone that = (SimpleTimeZone) obj;
return getID().equals(that.getID()) &&
hasSameRules(that);
}
/**
* Returns <code>true</code> if this zone has the same rules and offset as another zone.
* @param other the TimeZone object to be compared with
* @return <code>true</code> if the given zone is a SimpleTimeZone and has the
* same rules and offset as this one
* @since 1.2
*/
public boolean hasSameRules(TimeZone other) {
if (this == other) {
return true;
}
if (!(other instanceof SimpleTimeZone)) {
return false;
}
SimpleTimeZone that = (SimpleTimeZone) other;
return rawOffset == that.rawOffset &&
useDaylight == that.useDaylight &&
(!useDaylight
// Only check rules if using DST
|| (dstSavings == that.dstSavings &&
startMode == that.startMode &&
startMonth == that.startMonth &&
startDay == that.startDay &&
startDayOfWeek == that.startDayOfWeek &&
startTime == that.startTime &&
startTimeMode == that.startTimeMode &&
endMode == that.endMode &&
endMonth == that.endMonth &&
endDay == that.endDay &&
endDayOfWeek == that.endDayOfWeek &&
endTime == that.endTime &&
endTimeMode == that.endTimeMode &&
startYear == that.startYear));
}
/**
* Returns a string representation of this time zone.
* @return a string representation of this time zone.
*/
public String toString() {
return getClass().getName() +
"[id=" + getID() +
",offset=" + rawOffset +
",dstSavings=" + dstSavings +
",useDaylight=" + useDaylight +
",startYear=" + startYear +
",startMode=" + startMode +
",startMonth=" + startMonth +
",startDay=" + startDay +
",startDayOfWeek=" + startDayOfWeek +
",startTime=" + startTime +
",startTimeMode=" + startTimeMode +
",endMode=" + endMode +
",endMonth=" + endMonth +
",endDay=" + endDay +
",endDayOfWeek=" + endDayOfWeek +
",endTime=" + endTime +
",endTimeMode=" + endTimeMode + ']';
}
// =======================privates===============================
/**
* The month in which daylight saving time starts. This value must be
* between <code>Calendar.JANUARY</code> and
* <code>Calendar.DECEMBER</code> inclusive. This value must not equal
* <code>endMonth</code>.
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
*/
private int startMonth;
/**
* This field has two possible interpretations:
* <dl>
* <dt><code>startMode == DOW_IN_MONTH</code></dt>
* <dd>
* <code>startDay</code> indicates the day of the month of
* <code>startMonth</code> on which daylight
* saving time starts, from 1 to 28, 30, or 31, depending on the
* <code>startMonth</code>.
* </dd>
* <dt><code>startMode != DOW_IN_MONTH</code></dt>
* <dd>
* <code>startDay</code> indicates which <code>startDayOfWeek</code> in the
* month <code>startMonth</code> daylight
* saving time starts on. For example, a value of +1 and a
* <code>startDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the
* first Sunday of <code>startMonth</code>. Likewise, +2 would indicate the
* second Sunday, and -1 the last Sunday. A value of 0 is illegal.
* </dd>
* </dl>
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
*/
private int startDay;
/**
* The day of the week on which daylight saving time starts. This value
* must be between <code>Calendar.SUNDAY</code> and
* <code>Calendar.SATURDAY</code> inclusive.
* <p>If <code>useDaylight</code> is false or
* <code>startMode == DAY_OF_MONTH</code>, this value is ignored.
* @serial
*/
private int startDayOfWeek;
/**
* The time in milliseconds after midnight at which daylight saving
* time starts. This value is expressed as wall time, standard time,
* or UTC time, depending on the setting of <code>startTimeMode</code>.
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
*/
private int startTime;
/**
* The format of startTime, either WALL_TIME, STANDARD_TIME, or UTC_TIME.
* @serial
* @since 1.3
*/
private int startTimeMode;
/**
* The month in which daylight saving time ends. This value must be
* between <code>Calendar.JANUARY</code> and
* <code>Calendar.UNDECIMBER</code>. This value must not equal
* <code>startMonth</code>.
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
*/
private int endMonth;
/**
* This field has two possible interpretations:
* <dl>
* <dt><code>endMode == DOW_IN_MONTH</code></dt>
* <dd>
* <code>endDay</code> indicates the day of the month of
* <code>endMonth</code> on which daylight
* saving time ends, from 1 to 28, 30, or 31, depending on the
* <code>endMonth</code>.
* </dd>
* <dt><code>endMode != DOW_IN_MONTH</code></dt>
* <dd>
* <code>endDay</code> indicates which <code>endDayOfWeek</code> in th
* month <code>endMonth</code> daylight
* saving time ends on. For example, a value of +1 and a
* <code>endDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the
* first Sunday of <code>endMonth</code>. Likewise, +2 would indicate the
* second Sunday, and -1 the last Sunday. A value of 0 is illegal.
* </dd>
* </dl>
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
*/
private int endDay;
/**
* The day of the week on which daylight saving time ends. This value
* must be between <code>Calendar.SUNDAY</code> and
* <code>Calendar.SATURDAY</code> inclusive.
* <p>If <code>useDaylight</code> is false or
* <code>endMode == DAY_OF_MONTH</code>, this value is ignored.
* @serial
*/
private int endDayOfWeek;
/**
* The time in milliseconds after midnight at which daylight saving
* time ends. This value is expressed as wall time, standard time,
* or UTC time, depending on the setting of <code>endTimeMode</code>.
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
*/
private int endTime;
/**
* The format of endTime, either <code>WALL_TIME</code>,
* <code>STANDARD_TIME</code>, or <code>UTC_TIME</code>.
* @serial
* @since 1.3
*/
private int endTimeMode;
/**
* The year in which daylight saving time is first observed. This is an {@link GregorianCalendar#AD AD}
* value. If this value is less than 1 then daylight saving time is observed
* for all <code>AD</code> years.
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
*/
private int startYear;
/**
* The offset in milliseconds between this zone and GMT. Negative offsets
* are to the west of Greenwich. To obtain local <em>standard</em> time,
* add the offset to GMT time. To obtain local wall time it may also be
* necessary to add <code>dstSavings</code>.
* @serial
*/
private int rawOffset;
/**
* A boolean value which is true if and only if this zone uses daylight
* saving time. If this value is false, several other fields are ignored.
* @serial
*/
private boolean useDaylight=false; // indicate if this time zone uses DST
private static final int millisPerHour = 60*60*1000;
private static final int millisPerDay = 24*millisPerHour;
/**
* This field was serialized in JDK 1.1, so we have to keep it that way
* to maintain serialization compatibility. However, there's no need to
* recreate the array each time we create a new time zone.
* @serial An array of bytes containing the values {31, 28, 31, 30, 31, 30,
* 31, 31, 30, 31, 30, 31}. This is ignored as of the Java 2 platform v1.2, however, it must
* be streamed out for compatibility with JDK 1.1.
*/
private final byte monthLength[] = staticMonthLength;
private static final byte staticMonthLength[] = {31,28,31,30,31,30,31,31,30,31,30,31};
private static final byte staticLeapMonthLength[] = {31,29,31,30,31,30,31,31,30,31,30,31};
/**
* Variables specifying the mode of the start rule. Takes the following
* values:
* <dl>
* <dt><code>DOM_MODE</code></dt>
* <dd>
* Exact day of week; e.g., March 1.
* </dd>
* <dt><code>DOW_IN_MONTH_MODE</code></dt>
* <dd>
* Day of week in month; e.g., last Sunday in March.
* </dd>
* <dt><code>DOW_GE_DOM_MODE</code></dt>
* <dd>
* Day of week after day of month; e.g., Sunday on or after March 15.
* </dd>
* <dt><code>DOW_LE_DOM_MODE</code></dt>
* <dd>
* Day of week before day of month; e.g., Sunday on or before March 15.
* </dd>
* </dl>
* The setting of this field affects the interpretation of the
* <code>startDay</code> field.
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
* @since 1.1.4
*/
private int startMode;
/**
* Variables specifying the mode of the end rule. Takes the following
* values:
* <dl>
* <dt><code>DOM_MODE</code></dt>
* <dd>
* Exact day of week; e.g., March 1.
* </dd>
* <dt><code>DOW_IN_MONTH_MODE</code></dt>
* <dd>
* Day of week in month; e.g., last Sunday in March.
* </dd>
* <dt><code>DOW_GE_DOM_MODE</code></dt>
* <dd>
* Day of week after day of month; e.g., Sunday on or after March 15.
* </dd>
* <dt><code>DOW_LE_DOM_MODE</code></dt>
* <dd>
* Day of week before day of month; e.g., Sunday on or before March 15.
* </dd>
* </dl>
* The setting of this field affects the interpretation of the
* <code>endDay</code> field.
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
* @since 1.1.4
*/
private int endMode;
/**
* A positive value indicating the amount of time saved during DST in
* milliseconds.
* Typically one hour (3600000); sometimes 30 minutes (1800000).
* <p>If <code>useDaylight</code> is false, this value is ignored.
* @serial
* @since 1.1.4
*/
private int dstSavings;
private static final Gregorian gcal = CalendarSystem.getGregorianCalendar();
/**
* Cache values representing a single period of daylight saving
* time. Cache.start is the start time (inclusive) of daylight
* saving time and Cache.end is the end time (exclusive).
*
* Cache.year has a year value if both Cache.start and Cache.end are
* in the same year. Cache.year is set to startYear - 1 if
* Cache.start and Cache.end are in different years.
* Cache.year is a long to support Integer.MIN_VALUE - 1 (JCK requirement).
*/
private static final class Cache {
final long year;
final long start;
final long end;
Cache(long year, long start, long end) {
this.year = year;
this.start = start;
this.end = end;
}
}
private transient volatile Cache cache;
/**
* Constants specifying values of startMode and endMode.
*/
private static final int DOM_MODE = 1; // Exact day of month, "Mar 1"
private static final int DOW_IN_MONTH_MODE = 2; // Day of week in month, "lastSun"
private static final int DOW_GE_DOM_MODE = 3; // Day of week after day of month, "Sun>=15"
private static final int DOW_LE_DOM_MODE = 4; // Day of week before day of month, "Sun<=21"
/**
* Constant for a mode of start or end time specified as wall clock
* time. Wall clock time is standard time for the onset rule, and
* daylight time for the end rule.
* @since 1.4
*/
public static final int WALL_TIME = 0; // Zero for backward compatibility
/**
* Constant for a mode of start or end time specified as standard time.
* @since 1.4
*/
public static final int STANDARD_TIME = 1;
/**
* Constant for a mode of start or end time specified as UTC. European
* Union rules are specified as UTC time, for example.
* @since 1.4
*/
public static final int UTC_TIME = 2;
// Proclaim compatibility with 1.1
static final long serialVersionUID = -403250971215465050L;
// the internal serial version which says which version was written
// - 0 (default) for version up to JDK 1.1.3
// - 1 for version from JDK 1.1.4, which includes 3 new fields
// - 2 for JDK 1.3, which includes 2 new fields
static final int currentSerialVersion = 2;
/**
* The version of the serialized data on the stream. Possible values:
* <dl>
* <dt><b>0</b> or not present on stream</dt>
* <dd>
* JDK 1.1.3 or earlier.
* </dd>
* <dt><b>1</b></dt>
* <dd>
* JDK 1.1.4 or later. Includes three new fields: <code>startMode</code>,
* <code>endMode</code>, and <code>dstSavings</code>.
* </dd>
* <dt><b>2</b></dt>
* <dd>
* JDK 1.3 or later. Includes two new fields: <code>startTimeMode</code>
* and <code>endTimeMode</code>.
* </dd>
* </dl>
* When streaming out this class, the most recent format
* and the highest allowable <code>serialVersionOnStream</code>
* is written.
* @serial
* @since 1.1.4
*/
private int serialVersionOnStream = currentSerialVersion;
// Maximum number of rules.
private static final int MAX_RULE_NUM = 6;
private void invalidateCache() {
cache = null;
}
//----------------------------------------------------------------------
// Rule representation
//
// We represent the following flavors of rules:
// 5 the fifth of the month
// lastSun the last Sunday in the month
// lastMon the last Monday in the month
// Sun>=8 first Sunday on or after the eighth
// Sun<=25 last Sunday on or before the 25th
// This is further complicated by the fact that we need to remain
// backward compatible with the 1.1 FCS. Finally, we need to minimize
// API changes. In order to satisfy these requirements, we support
// three representation systems, and we translate between them.
//
// INTERNAL REPRESENTATION
// This is the format SimpleTimeZone objects take after construction or
// streaming in is complete. Rules are represented directly, using an
// unencoded format. We will discuss the start rule only below; the end
// rule is analogous.
// startMode Takes on enumerated values DAY_OF_MONTH,
// DOW_IN_MONTH, DOW_AFTER_DOM, or DOW_BEFORE_DOM.
// startDay The day of the month, or for DOW_IN_MONTH mode, a
// value indicating which DOW, such as +1 for first,
// +2 for second, -1 for last, etc.
// startDayOfWeek The day of the week. Ignored for DAY_OF_MONTH.
//
// ENCODED REPRESENTATION
// This is the format accepted by the constructor and by setStartRule()
// and setEndRule(). It uses various combinations of positive, negative,
// and zero values to encode the different rules. This representation
// allows us to specify all the different rule flavors without altering
// the API.
// MODE startMonth startDay startDayOfWeek
// DOW_IN_MONTH_MODE >=0 !=0 >0
// DOM_MODE >=0 >0 ==0
// DOW_GE_DOM_MODE >=0 >0 <0
// DOW_LE_DOM_MODE >=0 <0 <0
// (no DST) don't care ==0 don't care
//
// STREAMED REPRESENTATION
// We must retain binary compatibility with the 1.1 FCS. The 1.1 code only
// handles DOW_IN_MONTH_MODE and non-DST mode, the latter indicated by the
// flag useDaylight. When we stream an object out, we translate into an
// approximate DOW_IN_MONTH_MODE representation so the object can be parsed
// and used by 1.1 code. Following that, we write out the full
// representation separately so that contemporary code can recognize and
// parse it. The full representation is written in a "packed" format,
// consisting of a version number, a length, and an array of bytes. Future
// versions of this class may specify different versions. If they wish to
// include additional data, they should do so by storing them after the
// packed representation below.
//----------------------------------------------------------------------
/**
* Given a set of encoded rules in startDay and startDayOfMonth, decode
* them and set the startMode appropriately. Do the same for endDay and
* endDayOfMonth. Upon entry, the day of week variables may be zero or
* negative, in order to indicate special modes. The day of month
* variables may also be negative. Upon exit, the mode variables will be
* set, and the day of week and day of month variables will be positive.
* This method also recognizes a startDay or endDay of zero as indicating
* no DST.
*/
private void decodeRules()
{
decodeStartRule();
decodeEndRule();
}
/**
* Decode the start rule and validate the parameters. The parameters are
* expected to be in encoded form, which represents the various rule modes
* by negating or zeroing certain values. Representation formats are:
* <p>
* <pre>
* DOW_IN_MONTH DOM DOW>=DOM DOW<=DOM no DST
* ------------ ----- -------- -------- ----------
* month 0..11 same same same don't care
* day -5..5 1..31 1..31 -1..-31 0
* dayOfWeek 1..7 0 -1..-7 -1..-7 don't care
* time 0..ONEDAY same same same don't care
* </pre>
* The range for month does not include UNDECIMBER since this class is
* really specific to GregorianCalendar, which does not use that month.
* The range for time includes ONEDAY (vs. ending at ONEDAY-1) because the
* end rule is an exclusive limit point. That is, the range of times that
* are in DST include those >= the start and < the end. For this reason,
* it should be possible to specify an end of ONEDAY in order to include the
* entire day. Although this is equivalent to time 0 of the following day,
* it's not always possible to specify that, for example, on December 31.
* While arguably the start range should still be 0..ONEDAY-1, we keep
* the start and end ranges the same for consistency.
*/
private void decodeStartRule() {
useDaylight = (startDay != 0) && (endDay != 0);
if (startDay != 0) {
if (startMonth < Calendar.JANUARY || startMonth > Calendar.DECEMBER) {
throw new IllegalArgumentException(
"Illegal start month " + startMonth);
}
if (startTime < 0 || startTime > millisPerDay) {
throw new IllegalArgumentException(
"Illegal start time " + startTime);
}
if (startDayOfWeek == 0) {
startMode = DOM_MODE;
} else {
if (startDayOfWeek > 0) {
startMode = DOW_IN_MONTH_MODE;
} else {
startDayOfWeek = -startDayOfWeek;
if (startDay > 0) {
startMode = DOW_GE_DOM_MODE;
} else {
startDay = -startDay;
startMode = DOW_LE_DOM_MODE;
}
}
if (startDayOfWeek > Calendar.SATURDAY) {
throw new IllegalArgumentException(
"Illegal start day of week " + startDayOfWeek);
}
}
if (startMode == DOW_IN_MONTH_MODE) {
if (startDay < -5 || startDay > 5) {
throw new IllegalArgumentException(
"Illegal start day of week in month " + startDay);
}
} else if (startDay < 1 || startDay > staticMonthLength[startMonth]) {
throw new IllegalArgumentException(
"Illegal start day " + startDay);
}
}
}
/**
* Decode the end rule and validate the parameters. This method is exactly
* analogous to decodeStartRule().
* @see decodeStartRule
*/
private void decodeEndRule() {
useDaylight = (startDay != 0) && (endDay != 0);
if (endDay != 0) {
if (endMonth < Calendar.JANUARY || endMonth > Calendar.DECEMBER) {
throw new IllegalArgumentException(
"Illegal end month " + endMonth);
}
if (endTime < 0 || endTime > millisPerDay) {
throw new IllegalArgumentException(
"Illegal end time " + endTime);
}
if (endDayOfWeek == 0) {
endMode = DOM_MODE;
} else {
if (endDayOfWeek > 0) {
endMode = DOW_IN_MONTH_MODE;
} else {
endDayOfWeek = -endDayOfWeek;
if (endDay > 0) {
endMode = DOW_GE_DOM_MODE;
} else {
endDay = -endDay;
endMode = DOW_LE_DOM_MODE;
}
}
if (endDayOfWeek > Calendar.SATURDAY) {
throw new IllegalArgumentException(
"Illegal end day of week " + endDayOfWeek);
}
}
if (endMode == DOW_IN_MONTH_MODE) {
if (endDay < -5 || endDay > 5) {
throw new IllegalArgumentException(
"Illegal end day of week in month " + endDay);
}
} else if (endDay < 1 || endDay > staticMonthLength[endMonth]) {
throw new IllegalArgumentException(
"Illegal end day " + endDay);
}
}
}
/**
* Make rules compatible to 1.1 FCS code. Since 1.1 FCS code only understands
* day-of-week-in-month rules, we must modify other modes of rules to their
* approximate equivalent in 1.1 FCS terms. This method is used when streaming
* out objects of this class. After it is called, the rules will be modified,
* with a possible loss of information. startMode and endMode will NOT be
* altered, even though semantically they should be set to DOW_IN_MONTH_MODE,
* since the rule modification is only intended to be temporary.
*/
private void makeRulesCompatible()
{
switch (startMode) {
case DOM_MODE:
startDay = 1 + (startDay / 7);
startDayOfWeek = Calendar.SUNDAY;
break;
case DOW_GE_DOM_MODE:
// A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE
// that is, Sun>=1 == firstSun.
if (startDay != 1) {
startDay = 1 + (startDay / 7);
}
break;
case DOW_LE_DOM_MODE:
if (startDay >= 30) {
startDay = -1;
} else {
startDay = 1 + (startDay / 7);
}
break;
}
switch (endMode) {
case DOM_MODE:
endDay = 1 + (endDay / 7);
endDayOfWeek = Calendar.SUNDAY;
break;
case DOW_GE_DOM_MODE:
// A day-of-month of 1 is equivalent to DOW_IN_MONTH_MODE
// that is, Sun>=1 == firstSun.
if (endDay != 1) {
endDay = 1 + (endDay / 7);
}
break;
case DOW_LE_DOM_MODE:
if (endDay >= 30) {
endDay = -1;
} else {
endDay = 1 + (endDay / 7);
}
break;
}
/*
* Adjust the start and end times to wall time. This works perfectly
* well unless it pushes into the next or previous day. If that
* happens, we attempt to adjust the day rule somewhat crudely. The day
* rules have been forced into DOW_IN_MONTH mode already, so we change
* the day of week to move forward or back by a day. It's possible to
* make a more refined adjustment of the original rules first, but in
* most cases this extra effort will go to waste once we adjust the day
* rules anyway.
*/
switch (startTimeMode) {
case UTC_TIME:
startTime += rawOffset;
break;
}
while (startTime < 0) {
startTime += millisPerDay;
startDayOfWeek = 1 + ((startDayOfWeek+5) % 7); // Back 1 day
}
while (startTime >= millisPerDay) {
startTime -= millisPerDay;
startDayOfWeek = 1 + (startDayOfWeek % 7); // Forward 1 day
}
switch (endTimeMode) {
case UTC_TIME:
endTime += rawOffset + dstSavings;
break;
case STANDARD_TIME:
endTime += dstSavings;
}
while (endTime < 0) {
endTime += millisPerDay;
endDayOfWeek = 1 + ((endDayOfWeek+5) % 7); // Back 1 day
}
while (endTime >= millisPerDay) {
endTime -= millisPerDay;
endDayOfWeek = 1 + (endDayOfWeek % 7); // Forward 1 day
}
}
/**
* Pack the start and end rules into an array of bytes. Only pack
* data which is not preserved by makeRulesCompatible.
*/
private byte[] packRules()
{
byte[] rules = new byte[MAX_RULE_NUM];
rules[0] = (byte)startDay;
rules[1] = (byte)startDayOfWeek;
rules[2] = (byte)endDay;
rules[3] = (byte)endDayOfWeek;
// As of serial version 2, include time modes
rules[4] = (byte)startTimeMode;
rules[5] = (byte)endTimeMode;
return rules;
}
/**
* Given an array of bytes produced by packRules, interpret them
* as the start and end rules.
*/
private void unpackRules(byte[] rules)
{
startDay = rules[0];
startDayOfWeek = rules[1];
endDay = rules[2];
endDayOfWeek = rules[3];
// As of serial version 2, include time modes
if (rules.length >= MAX_RULE_NUM) {
startTimeMode = rules[4];
endTimeMode = rules[5];
}
}
/**
* Pack the start and end times into an array of bytes. This is required
* as of serial version 2.
*/
private int[] packTimes() {
int[] times = new int[2];
times[0] = startTime;
times[1] = endTime;
return times;
}
/**
* Unpack the start and end times from an array of bytes. This is required
* as of serial version 2.
*/
private void unpackTimes(int[] times) {
startTime = times[0];
endTime = times[1];
}
/**
* Save the state of this object to a stream (i.e., serialize it).
*
* @serialData We write out two formats, a JDK 1.1 compatible format, using
* <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed
* by the full rules, in packed format, in the optional section. The
* optional section will be ignored by JDK 1.1 code upon stream in.
* <p> Contents of the optional section: The length of a byte array is
* emitted (int); this is 4 as of this release. The byte array of the given
* length is emitted. The contents of the byte array are the true values of
* the fields <code>startDay</code>, <code>startDayOfWeek</code>,
* <code>endDay</code>, and <code>endDayOfWeek</code>. The values of these
* fields in the required section are approximate values suited to the rule
* mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by
* JDK 1.1.
*/
private void writeObject(ObjectOutputStream stream)
throws IOException
{
// Construct a binary rule
byte[] rules = packRules();
int[] times = packTimes();
// Convert to 1.1 FCS rules. This step may cause us to lose information.
makeRulesCompatible();
// Write out the 1.1 FCS rules
stream.defaultWriteObject();
// Write out the binary rules in the optional data area of the stream.
stream.writeInt(rules.length);
stream.write(rules);
stream.writeObject(times);
// Recover the original rules. This recovers the information lost
// by makeRulesCompatible.
unpackRules(rules);
unpackTimes(times);
}
/**
* Reconstitute this object from a stream (i.e., deserialize it).
*
* We handle both JDK 1.1
* binary formats and full formats with a packed byte array.
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException
{
stream.defaultReadObject();
if (serialVersionOnStream < 1) {
// Fix a bug in the 1.1 SimpleTimeZone code -- namely,
// startDayOfWeek and endDayOfWeek were usually uninitialized. We can't do
// too much, so we assume SUNDAY, which actually works most of the time.
if (startDayOfWeek == 0) {
startDayOfWeek = Calendar.SUNDAY;
}
if (endDayOfWeek == 0) {
endDayOfWeek = Calendar.SUNDAY;
}
// The variables dstSavings, startMode, and endMode are post-1.1, so they
// won't be present if we're reading from a 1.1 stream. Fix them up.
startMode = endMode = DOW_IN_MONTH_MODE;
dstSavings = millisPerHour;
} else {
// For 1.1.4, in addition to the 3 new instance variables, we also
// store the actual rules (which have not be made compatible with 1.1)
// in the optional area. Read them in here and parse them.
int length = stream.readInt();
if (length <= MAX_RULE_NUM) {
byte[] rules = new byte[length];
stream.readFully(rules);
unpackRules(rules);
} else {
throw new InvalidObjectException("Too many rules: " + length);
}
}
if (serialVersionOnStream >= 2) {
int[] times = (int[]) stream.readObject();
unpackTimes(times);
}
serialVersionOnStream = currentSerialVersion;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gwdcode/jdk11.0.2lib.src.java.base.java.git
git@gitee.com:gwdcode/jdk11.0.2lib.src.java.base.java.git
gwdcode
jdk11.0.2lib.src.java.base.java
JDK11.0.2-lib.src.java.base.java
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /