Java Code Examples for sun.util.calendar.ZoneInfoFile#getCustomTimeZone()
The following examples show how to use
sun.util.calendar.ZoneInfoFile#getCustomTimeZone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeZone.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 2
Source File: TimeZone.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 3
Source File: TimeZone.java From jdk-1.7-annotated with Apache License 2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 4
Source File: TimeZone.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 5
Source File: TimeZone.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 6
Source File: TimeZone.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 7
Source File: TimeZone.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 8
Source File: TimeZone.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 9
Source File: TimeZone.java From Java8CN with Apache License 2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 10
Source File: TimeZone.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 11
Source File: TimeZone.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 12
Source File: TimeZone.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 13
Source File: TimeZone.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 14
Source File: TimeZone.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 15
Source File: TimeZone.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 16
Source File: TimeZone.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 17
Source File: TimeZone.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }
Example 18
Source File: TimeZone.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Parses a custom time zone identifier and returns a corresponding zone. * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm) * * @param id a string of the <a href="#CustomID">custom ID form</a>. * @return a newly created TimeZone with the given offset and * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { int length; // Error if the length of id isn't long enough or id doesn't // start with "GMT". if ((length = id.length()) < (GMT_ID_LENGTH + 2) || id.indexOf(GMT_ID) != 0) { return null; } ZoneInfo zi; // First, we try to find it in the cache with the given // id. Even the id is not normalized, the returned ZoneInfo // should have its normalized id. zi = ZoneInfoFile.getZoneInfo(id); if (zi != null) { return zi; } int index = GMT_ID_LENGTH; boolean negative = false; char c = id.charAt(index++); if (c == '-') { negative = true; } else if (c != '+') { return null; } int hours = 0; int num = 0; int countDelim = 0; int len = 0; while (index < length) { c = id.charAt(index++); if (c == ':') { if (countDelim > 0) { return null; } if (len > 2) { return null; } hours = num; countDelim++; num = 0; len = 0; continue; } if (c < '0' || c > '9') { return null; } num = num * 10 + (c - '0'); len++; } if (index != length) { return null; } if (countDelim == 0) { if (len <= 2) { hours = num; num = 0; } else { hours = num / 100; num %= 100; } } else { if (len != 2) { return null; } } if (hours > 23 || num > 59) { return null; } int gmtOffset = (hours * 60 + num) * 60 * 1000; if (gmtOffset == 0) { zi = ZoneInfoFile.getZoneInfo(GMT_ID); if (negative) { zi.setID("GMT-00:00"); } else { zi.setID("GMT+00:00"); } } else { zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); } return zi; }