List of usage examples for java.util Calendar DST_OFFSET
int DST_OFFSET
To view the source code for java.util Calendar DST_OFFSET.
Click Source Link
get
and set
indicating the daylight saving offset in milliseconds. From source file:org.betaconceptframework.astroboa.portal.utility.CalendarUtils.java
public void clearTimeFromCalendar(Calendar calendar) { if (calendar != null) { calendar.set(Calendar.HOUR, 0); calendar.clear(Calendar.AM_PM); //ALWAYS clear AM_PM before HOUR_OF_DAY calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.clear(Calendar.DST_OFFSET); calendar.clear(Calendar.ZONE_OFFSET); }//from w ww . jav a 2 s . c o m }
From source file:org.exoplatform.contact.CalendarUtils.java
public static Calendar getInstanceTempCalendar() { Calendar calendar = GregorianCalendar.getInstance(); calendar.setLenient(false);/*www. j a va2 s . com*/ int gmtoffset = calendar.get(Calendar.DST_OFFSET) + calendar.get(Calendar.ZONE_OFFSET); calendar.setTimeInMillis(System.currentTimeMillis() - gmtoffset); return calendar; }
From source file:com.wavemaker.runtime.server.ServerUtils.java
/** * Calculate the server time offset against UTC * /*from www.j a v a 2 s . co m*/ * @return the server time offset in mili-seconds */ public static int getServerTimeOffset() { Calendar now = Calendar.getInstance(); return now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET); }
From source file:org.exoplatform.cms.common.CommonUtils.java
/** * Get current time GMT/Zulu or UTC,(zone time is 0+GMT) * @return Calendar /*from w ww. j a v a2 s .c o m*/ */ static public Calendar getGreenwichMeanTime() { Calendar calendar = GregorianCalendar.getInstance(); calendar.setLenient(false); int gmtoffset = calendar.get(Calendar.DST_OFFSET) + calendar.get(Calendar.ZONE_OFFSET); calendar.setTimeInMillis(System.currentTimeMillis() - gmtoffset); return calendar; }
From source file:org.openbravo.service.json.DataToJsonConverter.java
private static Date convertToUTC(Date localTime) { Calendar now = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.setTime(localTime);/*from www . j a va 2 s . co m*/ calendar.set(Calendar.DATE, now.get(Calendar.DATE)); calendar.set(Calendar.MONTH, now.get(Calendar.MONTH)); calendar.set(Calendar.YEAR, now.get(Calendar.YEAR)); int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET)); calendar.add(Calendar.MILLISECOND, -gmtMillisecondOffset); return calendar.getTime(); }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
/** * Converts a given string into a date. Code from Axis1 DateDeserializer. * * @param source// ww w. j av a 2 s. c om * @return Returns Date. */ public static Date convertToDate(String source) { // the lexical form of the date is '-'? yyyy '-' mm '-' dd zzzzzz? if ((source == null) || source.trim().equals("")) { return null; } source = source.trim(); boolean bc = false; if (source.startsWith("-")) { source = source.substring(1); bc = true; } int year = 0; int month = 0; int day = 0; int timeZoneOffSet = TimeZone.getDefault().getRawOffset(); if (source.length() >= 10) { //first 10 numbers must give the year if ((source.charAt(4) != '-') || (source.charAt(7) != '-')) { throw new RuntimeException("invalid date format (" + source + ") with out - s at correct place "); } year = Integer.parseInt(source.substring(0, 4)); month = Integer.parseInt(source.substring(5, 7)); day = Integer.parseInt(source.substring(8, 10)); if (source.length() > 10) { String restpart = source.substring(10); if (restpart.startsWith("Z")) { // this is a gmt time zone value timeZoneOffSet = 0; } else if (restpart.startsWith("+") || restpart.startsWith("-")) { // this is a specific time format string if (restpart.charAt(3) != ':') { throw new RuntimeException( "invalid time zone format (" + source + ") without : at correct place"); } int hours = Integer.parseInt(restpart.substring(1, 3)); int minits = Integer.parseInt(restpart.substring(4, 6)); timeZoneOffSet = ((hours * 60) + minits) * 60000; if (restpart.startsWith("-")) { timeZoneOffSet = timeZoneOffSet * -1; } } else { throw new RuntimeException("In valid string sufix"); } } } else { throw new RuntimeException("In valid string to parse"); } Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setLenient(false); calendar.set(Calendar.YEAR, year); //xml month stars from the 1 and calendar month is starts with 0 calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.ZONE_OFFSET, timeZoneOffSet); // set the day light off set only if time zone if (source.length() >= 10) { calendar.set(Calendar.DST_OFFSET, 0); } calendar.getTimeInMillis(); if (bc) { calendar.set(Calendar.ERA, GregorianCalendar.BC); } return calendar.getTime(); }
From source file:org.openbravo.service.json.AdvancedQueryBuilder.java
private String parseSingleClause(JSONObject jsonCriteria) throws JSONException { String operator = jsonCriteria.getString(OPERATOR_KEY); if (operator.equals(OPERATOR_BETWEEN) || operator.equals(OPERATOR_BETWEENINCLUSIVE) || operator.equals(OPERATOR_IBETWEEN) || operator.equals(OPERATOR_IBETWEENINCLUSIVE)) { return parseBetween(jsonCriteria, operator, true); }/* w w w .j a v a2 s. c om*/ Object value = jsonCriteria.has(VALUE_KEY) ? jsonCriteria.get(VALUE_KEY) : null; if (operator.equals(OPERATOR_EXISTS)) { String query = jsonCriteria.getString(EXISTS_QUERY_KEY); String alias = getTypedParameterAlias(); query = query.replace(EXISTS_VALUE_HOLDER, alias); final List<Object> typedValues = new ArrayList<Object>(); final JSONArray values = (JSONArray) value; for (int i = 0; i < values.length(); i++) { typedValues.add(values.getString(i)); } typedParameters.add(typedValues); return query; } String fieldName = jsonCriteria.getString(FIELD_NAME_KEY); // translate to a OR for each value if (value instanceof JSONArray) { final JSONArray jsonArray = (JSONArray) value; final JSONObject advancedCriteria = new JSONObject(); advancedCriteria.put(OPERATOR_KEY, OPERATOR_OR); final JSONArray subCriteria = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject subCriterion = new JSONObject(); subCriterion.put(OPERATOR_KEY, operator); subCriterion.put(FIELD_NAME_KEY, fieldName); subCriterion.put(VALUE_KEY, jsonArray.get(i)); subCriteria.put(i, subCriterion); } advancedCriteria.put(CRITERIA_KEY, subCriteria); return parseAdvancedCriteria(advancedCriteria); } // Retrieves the UTC time zone offset of the client if (jsonCriteria.has("minutesTimezoneOffset")) { int clientMinutesTimezoneOffset = Integer .parseInt(jsonCriteria.get("minutesTimezoneOffset").toString()); Calendar now = Calendar.getInstance(); // Obtains the UTC time zone offset of the server int serverMinutesTimezoneOffset = (now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET)) / (1000 * 60); // Obtains the time zone offset between the server and the client clientUTCMinutesTimeZoneDiff = clientMinutesTimezoneOffset; UTCServerMinutesTimeZoneDiff = serverMinutesTimezoneOffset; } if (operator.equals(OPERATOR_ISNULL) || operator.equals(OPERATOR_NOTNULL)) { value = null; } // if a comparison is done on an equal date then replace // with a between start time and end time on that date if (operator.equals(OPERATOR_EQUALS) || operator.equals(OPERATOR_EQUALSFIELD)) { final List<Property> properties = JsonUtils.getPropertiesOnPath(getEntity(), fieldName); if (properties.isEmpty()) { return null; } final Property property = properties.get(properties.size() - 1); if (property == null) { return null; } // create the clauses, re-uses the code in parseSimpleClause // which translates a lesserthan/greater than to the end/start // time of a date if (property.isDate() || property.isDatetime() || property.isAbsoluteDateTime()) { if (operator.equals(OPERATOR_EQUALS)) { return "(" + parseSimpleClause(fieldName, OPERATOR_GREATEROREQUAL, value) + " and " + parseSimpleClause(fieldName, OPERATOR_LESSOREQUAL, value) + ")"; } else { return "(" + parseSimpleClause(fieldName, OPERATOR_GREATEROREQUALFIELD, value) + " and " + parseSimpleClause(fieldName, OPERATOR_LESSOREQUALFIElD, value) + ")"; } } } return parseSimpleClause(fieldName, operator, value); }
From source file:org.openmrs.module.atomfeed.AtomFeedUtil.java
/** * Format dates as specified in rfc3339 (required for Atom dates) * /*from www . j ava 2 s . c o m*/ * @param d the Date to be formatted * @return the formatted date * @should not fail given a null date * @should convert date to rfc */ public static String dateToRFC3339(Date d) { if (d == null) return null; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(RFC_3339_DATE_FORMAT); Calendar cal = new GregorianCalendar(); cal.setTime(d); cal.setTimeZone(TimeZone.getDefault()); simpleDateFormat.setCalendar(cal); StringBuilder result = new StringBuilder(simpleDateFormat.format(d)); int offset_millis = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); int offset_hours = Math.abs(offset_millis / (1000 * 60 * 60)); int offset_minutes = Math.abs((offset_millis / (1000 * 60)) % 60); if (offset_millis == 0) { result.append("Z"); } else { result.append((offset_millis > 0) ? "+" : "-").append(doubleDigit.format(offset_hours)).append(":") .append(doubleDigit.format(offset_minutes)); } return result.toString(); }
From source file:com.zimbra.cs.imap.ImapRequest.java
Date readDate(boolean datetime, boolean checkRange) throws ImapParseException { String dateStr = (peekChar() == '"' ? readQuoted() : readAtom()); if (dateStr.length() < (datetime ? 26 : 10)) { throw new ImapParseException(tag, "invalid date format"); }/*from w w w . ja va2s . c o m*/ Calendar cal = new GregorianCalendar(); cal.clear(); int pos = 0, count; if (datetime && dateStr.charAt(0) == ' ') { pos++; } count = 2 - pos - (datetime || dateStr.charAt(1) != '-' ? 0 : 1); validateDigits(dateStr, pos, count, cal, Calendar.DAY_OF_MONTH); pos += count; validateChar(dateStr, pos, '-'); pos++; validateMonth(dateStr, pos, cal); pos += 3; validateChar(dateStr, pos, '-'); pos++; validateDigits(dateStr, pos, 4, cal, Calendar.YEAR); pos += 4; if (datetime) { validateChar(dateStr, pos, ' '); pos++; validateDigits(dateStr, pos, 2, cal, Calendar.HOUR); pos += 2; validateChar(dateStr, pos, ':'); pos++; validateDigits(dateStr, pos, 2, cal, Calendar.MINUTE); pos += 2; validateChar(dateStr, pos, ':'); pos++; validateDigits(dateStr, pos, 2, cal, Calendar.SECOND); pos += 2; validateChar(dateStr, pos, ' '); pos++; boolean zonesign = dateStr.charAt(pos) == '+'; validateChar(dateStr, pos, zonesign ? '+' : '-'); pos++; int zonehrs = validateDigits(dateStr, pos, 2, cal, -1); pos += 2; int zonemins = validateDigits(dateStr, pos, 2, cal, -1); pos += 2; cal.set(Calendar.ZONE_OFFSET, (zonesign ? 1 : -1) * (60 * zonehrs + zonemins) * 60000); cal.set(Calendar.DST_OFFSET, 0); } if (pos != dateStr.length()) { throw new ImapParseException(tag, "excess characters at end of date string"); } Date date = cal.getTime(); if (checkRange && date.getTime() < 0) { throw new ImapParseException(tag, "date out of range"); } return date; }
From source file:processing.app.debug.Compiler.java
private PreferencesMap createBuildPreferences(String _buildPath, String _primaryClassName) throws RunnerException { if (BaseNoGui.getBoardPreferences() == null) { RunnerException re = new RunnerException( _("No board selected; please choose a board from the Tools > Board menu.")); re.hideStackTrace();/*from w ww .j ava 2s . c om*/ throw re; } // Check if the board needs a platform from another package TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); TargetPlatform corePlatform = null; PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences(); String core = boardPreferences.get("build.core", "arduino"); if (core.contains(":")) { String[] split = core.split(":"); core = split[1]; corePlatform = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); if (corePlatform == null) { RunnerException re = new RunnerException( I18n.format(_("Selected board depends on '{0}' core (not installed)."), split[0])); re.hideStackTrace(); throw re; } } // Merge all the global preference configuration in order of priority PreferencesMap buildPref = new PreferencesMap(); buildPref.putAll(PreferencesData.getMap()); if (corePlatform != null) { buildPref.putAll(corePlatform.getPreferences()); } buildPref.putAll(targetPlatform.getPreferences()); buildPref.putAll(BaseNoGui.getBoardPreferences()); for (String k : buildPref.keySet()) { if (buildPref.get(k) == null) { buildPref.put(k, ""); } } buildPref.put("build.path", _buildPath); buildPref.put("build.project_name", _primaryClassName); buildPref.put("build.arch", targetPlatform.getId().toUpperCase()); // Platform.txt should define its own compiler.path. For // compatibility with earlier 1.5 versions, we define a (ugly, // avr-specific) default for it, but this should be removed at some // point. if (!buildPref.containsKey("compiler.path")) { System.err.println(_( "Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer.")); buildPref.put("compiler.path", BaseNoGui.getAvrBasePath()); } TargetPlatform referencePlatform = null; if (corePlatform != null) { referencePlatform = corePlatform; } else { referencePlatform = targetPlatform; } buildPref.put("build.platform.path", referencePlatform.getFolder().getAbsolutePath()); // Core folder File coreFolder = new File(referencePlatform.getFolder(), "cores"); coreFolder = new File(coreFolder, core); buildPref.put("build.core", core); buildPref.put("build.core.path", coreFolder.getAbsolutePath()); // System Folder File systemFolder = referencePlatform.getFolder(); systemFolder = new File(systemFolder, "system"); buildPref.put("build.system.path", systemFolder.getAbsolutePath()); // Variant Folder String variant = buildPref.get("build.variant"); if (variant != null) { TargetPlatform t; if (!variant.contains(":")) { t = targetPlatform; } else { String[] split = variant.split(":", 2); t = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId()); variant = split[1]; } File variantFolder = new File(t.getFolder(), "variants"); variantFolder = new File(variantFolder, variant); buildPref.put("build.variant.path", variantFolder.getAbsolutePath()); } else { buildPref.put("build.variant.path", ""); } ContributedPlatform installedPlatform = BaseNoGui.indexer .getInstalled(referencePlatform.getContainerPackage().getId(), referencePlatform.getId()); if (installedPlatform != null) { List<ContributedTool> tools = installedPlatform.getResolvedTools(); BaseNoGui.createToolPreferences(tools, false); } // Build Time GregorianCalendar cal = new GregorianCalendar(); long current = new Date().getTime() / 1000; long timezone = cal.get(Calendar.ZONE_OFFSET) / 1000; long daylight = cal.get(Calendar.DST_OFFSET) / 1000; buildPref.put("extra.time.utc", Long.toString(current)); buildPref.put("extra.time.local", Long.toString(current + timezone + daylight)); buildPref.put("extra.time.zone", Long.toString(timezone)); buildPref.put("extra.time.dst", Long.toString(daylight)); List<Map.Entry<String, String>> unsetPrefs = buildPref.entrySet().stream() .filter(entry -> Constants.PREF_REMOVE_PLACEHOLDER.equals(entry.getValue())) .collect(Collectors.toList()); buildPref.entrySet().stream().filter(entry -> { return unsetPrefs.stream().filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey())) .count() > 0; }).forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), "")); return buildPref; }