List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:org.apache.oozie.coord.CoordELFunctions.java
public static Calendar getEffectiveNominalTime() { Date datasetInitialInstance = getInitialInstance(); TimeZone dsTZ = getDatasetTZ(); // Convert Date to Calendar for corresponding TZ Calendar current = Calendar.getInstance(); current.setTime(datasetInitialInstance); current.setTimeZone(dsTZ); Calendar calEffectiveTime = Calendar.getInstance(); calEffectiveTime.setTime(getActionCreationtime()); calEffectiveTime.setTimeZone(dsTZ);/*from www . j a v a 2 s. c o m*/ if (current.compareTo(calEffectiveTime) > 0) { // Nominal Time < initial Instance // TODO: getClass() call doesn't work from static method. // XLog.getLog("CoordELFunction.class").warn("ACTION CREATED BEFORE INITIAL INSTACE "+ // current.getTime()); return null; } return calEffectiveTime; }
From source file:org.apache.oozie.coord.CoordELFunctions.java
/** * Returns a date string that is offset from 'strBaseDate' by the difference from Oozie processing timezone to the given * timezone. It will account for daylight saving time based on the given 'strBaseDate' and 'timezone'. * * @param strBaseDate The base date/* ww w .ja v a 2s. c o m*/ * @param timezone * @return the offset date string * @throws Exception */ public static String ph2_coord_dateTzOffset(String strBaseDate, String timezone) throws Exception { Calendar baseCalDate = DateUtils.getCalendar(strBaseDate); StringBuilder buffer = new StringBuilder(); baseCalDate.setTimeZone(DateUtils.getTimeZone(timezone)); buffer.append(DateUtils.formatDate(baseCalDate)); return buffer.toString(); }
From source file:org.apache.oozie.coord.CoordELFunctions.java
/** * Find the current instance based on effectiveTime (i.e Action_Creation_Time or Action_Start_Time) * * @return current instance i.e. current(0) returns null if effectiveTime is earlier than Initial Instance time of * the dataset.// w ww. jav a 2 s. c o m */ private static Calendar getCurrentInstance_old(Date effectiveTime, int instanceCount[], ELEvaluator eval) { Date datasetInitialInstance = getInitialInstance(eval); TimeUnit dsTimeUnit = getDSTimeUnit(eval); TimeZone dsTZ = getDatasetTZ(eval); int dsFreq = getDSFrequency(eval); // Convert Date to Calendar for corresponding TZ Calendar current = Calendar.getInstance(); current.setTime(datasetInitialInstance); current.setTimeZone(dsTZ); Calendar calEffectiveTime = Calendar.getInstance(); calEffectiveTime.setTime(effectiveTime); calEffectiveTime.setTimeZone(dsTZ); if (instanceCount == null) { // caller doesn't care about this value instanceCount = new int[1]; } instanceCount[0] = 0; if (current.compareTo(calEffectiveTime) > 0) { return null; } Calendar origCurrent = (Calendar) current.clone(); while (current.compareTo(calEffectiveTime) <= 0) { current = (Calendar) origCurrent.clone(); instanceCount[0]++; current.add(dsTimeUnit.getCalendarUnit(), instanceCount[0] * dsFreq); } instanceCount[0]--; current = (Calendar) origCurrent.clone(); current.add(dsTimeUnit.getCalendarUnit(), instanceCount[0] * dsFreq); return current; }
From source file:com.haulmont.cuba.web.gui.components.WebDateField.java
protected Date constructDate() { final Date datePickerDate = dateField.getValue(); if (datePickerDate == null) { return null; }/*from w w w .j av a2 s.c om*/ Calendar dateCalendar = Calendar.getInstance(userSession.getLocale()); if (timeZone != null) { dateCalendar.setTimeZone(timeZone); } dateCalendar.setTime(datePickerDate); if (timeField.getValue() == null) { dateCalendar.set(Calendar.HOUR_OF_DAY, 0); dateCalendar.set(Calendar.MINUTE, 0); dateCalendar.set(Calendar.SECOND, 0); } else { Calendar timeCalendar = Calendar.getInstance(userSession.getLocale()); timeCalendar.setTime(timeField.<Date>getValue()); dateCalendar.set(Calendar.HOUR_OF_DAY, timeCalendar.get(Calendar.HOUR_OF_DAY)); dateCalendar.set(Calendar.MINUTE, timeCalendar.get(Calendar.MINUTE)); dateCalendar.set(Calendar.SECOND, timeCalendar.get(Calendar.SECOND)); } Date resultDate = dateCalendar.getTime(); if (metaProperty != null) { Class javaClass = metaProperty.getRange().asDatatype().getJavaClass(); if (javaClass.equals(java.sql.Date.class)) { return new java.sql.Date(resultDate.getTime()); } else if (javaClass.equals(Time.class)) { return new Time(resultDate.getTime()); } else { return resultDate; } } else { return resultDate; } }
From source file:org.openhab.binding.keba.internal.handler.KeContactHandler.java
protected void onData(ByteBuffer byteBuffer) { String response = new String(byteBuffer.array(), 0, byteBuffer.limit()); response = StringUtils.chomp(response); if (response.contains("TCH-OK")) { // ignore confirmation messages which are not JSON return;/*from w w w .j a va 2 s . c o m*/ } try { JsonObject readObject = parser.parse(response).getAsJsonObject(); for (Entry<String, JsonElement> entry : readObject.entrySet()) { switch (entry.getKey()) { case "Product": { Map<String, String> properties = editProperties(); String product = entry.getValue().getAsString().trim(); properties.put(CHANNEL_MODEL, product); updateProperties(properties); if (product.contains("P20")) { type = KebaType.P20; } else if (product.contains("P30")) { type = KebaType.P30; } series = KebaSeries.getSeries(product.substring(13, 14).charAt(0)); break; } case "Serial": { Map<String, String> properties = editProperties(); properties.put(CHANNEL_SERIAL, entry.getValue().getAsString()); updateProperties(properties); break; } case "Firmware": { Map<String, String> properties = editProperties(); properties.put(CHANNEL_FIRMWARE, entry.getValue().getAsString()); updateProperties(properties); break; } case "Plug": { int state = entry.getValue().getAsInt(); switch (state) { case 0: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_WALLBOX), OnOffType.OFF); updateState(new ChannelUID(getThing().getUID(), CHANNEL_VEHICLE), OnOffType.OFF); updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLUG_LOCKED), OnOffType.OFF); break; } case 1: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_WALLBOX), OnOffType.ON); updateState(new ChannelUID(getThing().getUID(), CHANNEL_VEHICLE), OnOffType.OFF); updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLUG_LOCKED), OnOffType.OFF); break; } case 3: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_WALLBOX), OnOffType.ON); updateState(new ChannelUID(getThing().getUID(), CHANNEL_VEHICLE), OnOffType.OFF); updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLUG_LOCKED), OnOffType.ON); break; } case 5: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_WALLBOX), OnOffType.ON); updateState(new ChannelUID(getThing().getUID(), CHANNEL_VEHICLE), OnOffType.ON); updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLUG_LOCKED), OnOffType.OFF); break; } case 7: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_WALLBOX), OnOffType.ON); updateState(new ChannelUID(getThing().getUID(), CHANNEL_VEHICLE), OnOffType.ON); updateState(new ChannelUID(getThing().getUID(), CHANNEL_PLUG_LOCKED), OnOffType.ON); break; } } break; } case "State": { State newState = new DecimalType(entry.getValue().getAsInt()); updateState(new ChannelUID(getThing().getUID(), CHANNEL_STATE), newState); break; } case "Enable sys": { int state = entry.getValue().getAsInt(); switch (state) { case 1: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_ENABLED), OnOffType.ON); break; } default: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_ENABLED), OnOffType.OFF); break; } } break; } case "Curr HW": { int state = entry.getValue().getAsInt(); maxSystemCurrent = state; State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_MAX_SYSTEM_CURRENT), newState); if (maxSystemCurrent != 0) { if (maxSystemCurrent < maxPresetCurrent) { transceiver.send("curr " + String.valueOf(maxSystemCurrent), this); updateState(new ChannelUID(getThing().getUID(), CHANNEL_MAX_PRESET_CURRENT), new DecimalType(maxSystemCurrent)); updateState(new ChannelUID(getThing().getUID(), CHANNEL_MAX_PRESET_CURRENT_RANGE), new PercentType((maxSystemCurrent - 6000) * 100 / (maxSystemCurrent - 6000))); } } else { logger.debug("maxSystemCurrent is 0. Ignoring."); } break; } case "Curr user": { int state = entry.getValue().getAsInt(); maxPresetCurrent = state; updateState(new ChannelUID(getThing().getUID(), CHANNEL_MAX_PRESET_CURRENT), new DecimalType(state)); if (maxSystemCurrent != 0) { updateState(new ChannelUID(getThing().getUID(), CHANNEL_MAX_PRESET_CURRENT_RANGE), new PercentType(Math.min(100, (state - 6000) * 100 / (maxSystemCurrent - 6000)))); } break; } case "Curr FS": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_FAILSAFE_CURRENT), newState); break; } case "Max curr": { int state = entry.getValue().getAsInt(); maxPresetCurrent = state; updateState(new ChannelUID(getThing().getUID(), CHANNEL_PILOT_CURRENT), new DecimalType(state)); updateState(new ChannelUID(getThing().getUID(), CHANNEL_PILOT_PWM), new DecimalType(state)); break; } case "Output": { int state = entry.getValue().getAsInt(); switch (state) { case 1: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_OUTPUT), OnOffType.ON); break; } default: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_OUTPUT), OnOffType.OFF); break; } } break; } case "Input": { int state = entry.getValue().getAsInt(); switch (state) { case 1: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_INPUT), OnOffType.ON); break; } default: { updateState(new ChannelUID(getThing().getUID(), CHANNEL_INPUT), OnOffType.OFF); break; } } break; } case "Sec": { long state = entry.getValue().getAsLong(); Calendar uptime = Calendar.getInstance(); uptime.setTimeZone(TimeZone.getTimeZone("GMT")); uptime.setTimeInMillis(state * 1000); SimpleDateFormat pFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); pFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); updateState(new ChannelUID(getThing().getUID(), CHANNEL_UPTIME), new DateTimeType(pFormatter.format(uptime.getTime()))); break; } case "U1": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_U1), newState); break; } case "U2": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_U2), newState); break; } case "U3": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_U3), newState); break; } case "I1": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_I1), newState); break; } case "I2": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_I2), newState); break; } case "I3": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_I3), newState); break; } case "P": { long state = entry.getValue().getAsLong(); State newState = new DecimalType(state / 1000); updateState(new ChannelUID(getThing().getUID(), CHANNEL_POWER), newState); break; } case "PF": { int state = entry.getValue().getAsInt(); State newState = new PercentType(state / 10); updateState(new ChannelUID(getThing().getUID(), CHANNEL_POWER_FACTOR), newState); break; } case "E pres": { long state = entry.getValue().getAsLong(); State newState = new DecimalType(state / 10); updateState(new ChannelUID(getThing().getUID(), CHANNEL_SESSION_CONSUMPTION), newState); break; } case "E total": { long state = entry.getValue().getAsLong(); State newState = new DecimalType(state / 10); updateState(new ChannelUID(getThing().getUID(), CHANNEL_TOTAL_CONSUMPTION), newState); break; } case "AuthON": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_AUTHON), newState); break; } case "Authreq": { int state = entry.getValue().getAsInt(); State newState = new DecimalType(state); updateState(new ChannelUID(getThing().getUID(), CHANNEL_AUTHREQ), newState); break; } } } } catch (JsonParseException e) { logger.debug("Invalid JSON data will be ignored: '{}'", response); } }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static String convertToString(Date value) { if (isCustomClassPresent) { // this means user has define a seperate converter util class return invokeToStringMethod(value, Date.class); } else {/*w w w . j ava2 s. c om*/ // lexical form of the date is '-'? yyyy '-' mm '-' dd zzzzzz? Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(value); if (!calendar.isSet(Calendar.ZONE_OFFSET)) { calendar.setTimeZone(TimeZone.getDefault()); } StringBuffer dateString = new StringBuffer(16); appendDate(dateString, calendar); appendTimeZone(calendar, dateString); return dateString.toString(); } }
From source file:org.madeirahs.shared.provider.FTPProvider.java
/** * Obtains the last modification time of the file. * @param fileName//www. j a va 2 s. c o m * @return a Calendar object representing the last modification time of the file in the local time zone. */ public Calendar getLastModified(String fileName) { synchronized (ftp) { try { guard.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } try { FTPFile file = ftp.mlistFile(fileName); Calendar time = file.getTimestamp(); time.setTimeZone(TimeZone.getDefault()); return time; } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment.java
@Override public void onStart() { super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point AlertDialog d = (AlertDialog) getDialog(); if (d != null) { Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE); Button negativeButton = d.getButton(Dialog.BUTTON_NEGATIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override/* w w w . j a va2s . c o m*/ public void onClick(View v) { if (mUsageRadioGroup.getCheckedRadioButtonId() == -1) { Toast.makeText(getActivity(), R.string.edit_key_select_usage, Toast.LENGTH_LONG).show(); return; } // noinspection unchecked SupportedKeyType keyType = ((Choice<SupportedKeyType>) mKeyTypeSpinner.getSelectedItem()) .getId(); Curve curve = null; Integer keySize = null; Algorithm algorithm = null; // set keysize & curve, for RSA & ECC respectively switch (keyType) { case RSA_2048: { keySize = 2048; break; } case RSA_3072: { keySize = 3072; break; } case RSA_4096: { keySize = 4096; break; } case ECC_P256: { curve = Curve.NIST_P256; break; } case ECC_P521: { curve = Curve.NIST_P521; break; } } // set algorithm switch (keyType) { case RSA_2048: case RSA_3072: case RSA_4096: { algorithm = Algorithm.RSA; break; } case ECC_P256: case ECC_P521: { if (mUsageEncrypt.isChecked()) { algorithm = Algorithm.ECDH; } else { algorithm = Algorithm.ECDSA; } break; } } // set flags int flags = 0; if (mWillBeMasterKey) { flags |= KeyFlags.CERTIFY_OTHER; } if (mUsageSign.isChecked()) { flags |= KeyFlags.SIGN_DATA; } else if (mUsageEncrypt.isChecked()) { flags |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE; } else if (mUsageSignAndEncrypt.isChecked()) { flags |= KeyFlags.SIGN_DATA | KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE; } long expiry; if (mNoExpiryCheckBox.isChecked()) { expiry = 0L; } else { Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault()); //noinspection ResourceType selectedCal.set(mExpiryDatePicker.getYear(), mExpiryDatePicker.getMonth(), mExpiryDatePicker.getDayOfMonth()); // date picker uses default time zone, we need to convert to UTC selectedCal.setTimeZone(TimeZone.getTimeZone("UTC")); expiry = selectedCal.getTime().getTime() / 1000; } SaveKeyringParcel.SubkeyAdd newSubkey = new SaveKeyringParcel.SubkeyAdd(algorithm, keySize, curve, flags, expiry); mAlgorithmSelectedListener.onAlgorithmSelected(newSubkey); // finally, dismiss the dialogue dismiss(); } }); negativeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); } }
From source file:org.formix.dsx.serialization.XmlSerializer.java
/** * Parse a date. The defeualt implementation expects the following format: * ISO 8601: 1994-11-05T08:15:30-05:00// www.j ava 2 s.c om * * @param dateString * the date string to deserialize. * * @return the corresponding date object. * * @throws ParseException * Thrown if a parsing problem occurs. */ protected Date parseDate(String dateString) throws ParseException { Pattern p = Pattern.compile("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})([+-]\\d{2}:?\\d{2})?"); Matcher m = p.matcher(dateString); if (m.find()) { int[] dateTimeParts = new int[6]; String timeZone = ""; for (int g = 1; g <= m.groupCount(); g++) { String group = m.group(g); if (g < 7) dateTimeParts[g - 1] = Integer.parseInt(group); else if (m.group(g) != null) timeZone = m.group(g); } Calendar cal = Calendar.getInstance(); TimeZone tz = TimeZone.getTimeZone("GMT" + timeZone); cal.setTimeZone(tz); cal.set(Calendar.YEAR, dateTimeParts[0]); cal.set(Calendar.MONTH, dateTimeParts[1] - 1); cal.set(Calendar.DAY_OF_MONTH, dateTimeParts[2]); cal.set(Calendar.HOUR_OF_DAY, dateTimeParts[3]); cal.set(Calendar.MINUTE, dateTimeParts[4]); cal.set(Calendar.SECOND, dateTimeParts[5]); return cal.getTime(); } else { return null; } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopDateField.java
protected Date extractTime(Date date) { Calendar dateCalendar = Calendar.getInstance(userSession.getLocale()); if (timeZone != null) { dateCalendar.setTimeZone(timeZone); }/*from ww w.j a v a 2 s . c o m*/ dateCalendar.setTime(date); Calendar timeCalendar = Calendar.getInstance(userSession.getLocale()); timeCalendar.setTimeInMillis(0); timeCalendar.set(Calendar.HOUR_OF_DAY, dateCalendar.get(Calendar.HOUR_OF_DAY)); timeCalendar.set(Calendar.MINUTE, dateCalendar.get(Calendar.MINUTE)); timeCalendar.set(Calendar.SECOND, dateCalendar.get(Calendar.SECOND)); return timeCalendar.getTime(); }