List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:org.jfree.data.time.junit.HourTest.java
/** * Some checks for the getLastMillisecond() method. *//*from w w w . j a v a2 s.co m*/ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(1, 1, 1, 1970); assertEquals(3599999L, h.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:ca.uhn.fhir.model.primitive.BaseDateTimeDt.java
@Override protected Date parse(String theValue) throws DataFormatException { Calendar cal = new GregorianCalendar(0, 0, 0); cal.setTimeZone(TimeZone.getDefault()); String value = theValue;/*from w w w. j av a2 s . com*/ boolean fractionalSecondsSet = false; if (value.length() > 0 && (value.charAt(0) == ' ' || value.charAt(value.length() - 1) == ' ')) { value = value.trim(); } int length = value.length(); if (length == 0) { return null; } if (length < 4) { throwBadDateFormat(value); } TemporalPrecisionEnum precision = null; cal.set(Calendar.YEAR, parseInt(value, value.substring(0, 4), 0, 9999)); precision = TemporalPrecisionEnum.YEAR; if (length > 4) { validateCharAtIndexIs(value, 4, '-'); validateLengthIsAtLeast(value, 7); int monthVal = parseInt(value, value.substring(5, 7), 1, 12) - 1; cal.set(Calendar.MONTH, monthVal); precision = TemporalPrecisionEnum.MONTH; if (length > 7) { validateCharAtIndexIs(value, 7, '-'); validateLengthIsAtLeast(value, 10); cal.set(Calendar.DATE, 1); // for some reason getActualMaximum works incorrectly if date isn't set int actualMaximum = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum)); precision = TemporalPrecisionEnum.DAY; if (length > 10) { validateLengthIsAtLeast(value, 17); validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss int offsetIdx = getOffsetIndex(value); String time; if (offsetIdx == -1) { //throwBadDateFormat(theValue); // No offset - should this be an error? time = value.substring(11); } else { time = value.substring(11, offsetIdx); String offsetString = value.substring(offsetIdx); setTimeZone(value, offsetString); cal.setTimeZone(getTimeZone()); } int timeLength = time.length(); validateCharAtIndexIs(value, 13, ':'); cal.set(Calendar.HOUR_OF_DAY, parseInt(value, value.substring(11, 13), 0, 23)); cal.set(Calendar.MINUTE, parseInt(value, value.substring(14, 16), 0, 59)); precision = TemporalPrecisionEnum.MINUTE; if (timeLength > 5) { validateLengthIsAtLeast(value, 19); validateCharAtIndexIs(value, 16, ':'); // yyyy-mm-ddThh:mm:ss cal.set(Calendar.SECOND, parseInt(value, value.substring(17, 19), 0, 59)); precision = TemporalPrecisionEnum.SECOND; if (timeLength > 8) { validateCharAtIndexIs(value, 19, '.'); // yyyy-mm-ddThh:mm:ss.SSSS validateLengthIsAtLeast(value, 20); int endIndex = getOffsetIndex(value); if (endIndex == -1) { endIndex = value.length(); } int millis; String millisString; if (endIndex > 23) { myFractionalSeconds = value.substring(20, endIndex); fractionalSecondsSet = true; endIndex = 23; millisString = value.substring(20, endIndex); millis = parseInt(value, millisString, 0, 999); } else { millisString = value.substring(20, endIndex); millis = parseInt(value, millisString, 0, 999); myFractionalSeconds = millisString; fractionalSecondsSet = true; } if (millisString.length() == 1) { millis = millis * 100; } else if (millisString.length() == 2) { millis = millis * 10; } cal.set(Calendar.MILLISECOND, millis); precision = TemporalPrecisionEnum.MILLI; } } } } else { cal.set(Calendar.DATE, 1); } } else { cal.set(Calendar.DATE, 1); } if (fractionalSecondsSet == false) { myFractionalSeconds = ""; } setPrecision(precision); return cal.getTime(); }
From source file:com.funambol.json.gui.GuiServlet.java
private String doListAll(HttpServletRequest request) { String result = HTMLManager.getHtmlHeaderFor("Choose a group"); Repository rep = new Repository((String) request.getSession().getAttribute("username"), TimeZone.getDefault(), "UTF-8"); Iterator<String> it = rep.getGroupKeySet(); while (it.hasNext()) { String groupName = it.next(); result += " - " + HTMLManager.buildHRef(APPNAME, groupName, NameValuePair.parseFromStrings(ACTION, LIST, GROUP, groupName)) + " - " + HTMLManager.buildHRef(APPNAME, "Delete All", NameValuePair.parseFromStrings(ACTION, EMPTYGROUP, GROUP, groupName)) + "<br>"; }/*from w ww . j av a 2 s . co m*/ result += "<br>" + HTMLManager.createOneRowTable( HTMLManager.buildHRef(APPNAME, "Empty All", NameValuePair.parseFromStrings(ACTION, EMPTYALL)), HTMLManager.buildHRef("Home", APPNAME)) + "<br>"; result += HTMLManager.closePage(); return result; }
From source file:com.openerp.support.listview.OEListViewAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { viewRow = convertView;/*from www. j a v a2s. c o m*/ parentView = parent; LayoutInflater inflater = ((MainActivity) context).getLayoutInflater(); if (viewRow == null) { viewRow = inflater.inflate(this.resource_id, parent, false); } row = this.rows.get(position); rowdata = row.getRow_data(); for (final Integer control_id : controlClickHandler.keySet()) { viewRow.findViewById(control_id).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { controlClickHandler.get(control_id).controlClicked(position, rows.get(position), viewRow); } }); } for (int i = 0; i < this.to.length; i++) { final String key = from[i]; if (booleanEvents.contains(from[i])) { handleBinaryBackground(row.getRow_id(), key, to[i], viewRow, position); } else if (backgroundChange.containsKey(key)) { String backFlag = rowdata.get(key).toString(); if (!backFlag.equals("false")) { backFlag = "true"; } int color = backgroundChange.get(key).get(backFlag); viewRow.findViewById(this.to[i]).setBackgroundColor(color); continue; } else if (imageCols.contains(from[i])) { String data = rowdata.get(from[i]).toString(); if (!data.equals("false")) { ImageView imgView = (ImageView) viewRow.findViewById(this.to[i]); imgView.setImageBitmap(Base64Helper.getBitmapImage(context, data)); } } else { TextView txvObj = null; WebView webview = null; if (!webViewControls.containsKey(this.from[i])) { txvObj = (TextView) viewRow.findViewById(this.to[i]); } else { if (webViewControls.get(this.from[i])) { webview = (WebView) viewRow.findViewById(this.to[i]); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); } else { txvObj = (TextView) viewRow.findViewById(this.to[i]); } } String key_col = this.from[i]; String alt_key_col = key_col; if (key_col.contains("|")) { String[] splits = key_col.split("\\|"); key_col = splits[0]; alt_key_col = splits[1]; } String data = rowdata.get(key_col).toString(); if (data.equals("false") || TextUtils.isEmpty(data)) { data = rowdata.get(alt_key_col).toString(); } if (this.cleanColumn.contains(key_col)) { data = HTMLHelper.htmlToString(data); } if (datecols.contains(key_col)) { if (date_format != null) { data = OEDate.getDate(data, TimeZone.getDefault().getID(), date_format); } else { data = OEDate.getDate(data, TimeZone.getDefault().getID()); } } if (!data.equals("false")) { try { StringBuffer inputdata = new StringBuffer(); JSONArray tmpData = new JSONArray(data); for (int k = 0; k < tmpData.length(); k++) { if (tmpData.get(k) instanceof JSONArray) { if (tmpData.getJSONArray(k).length() == 2) { inputdata.append(tmpData.getJSONArray(k).getString(1)); inputdata.append(","); } } else { inputdata.append(tmpData.getString(0)); inputdata.append(","); } } int index = inputdata.lastIndexOf(","); if (index > 0) { inputdata.deleteCharAt(index); } txvObj.setText(inputdata.toString()); } catch (Exception e) { if (this.toHtml.contains(key_col)) { if (webViewControls.get(this.from[i])) { String customHtml = data; webview.loadData(customHtml, "text/html", "UTF-8"); } else { txvObj.setText(HTMLHelper.stringToHtml(data)); } } else { txvObj.setText(data); } } } else { txvObj.setText(""); } } } if (this.canChangeBackground && !viewRow.isSelected()) { boolean flag = Boolean.parseBoolean(rowdata.get(conditionKey).toString()); if (flag) { viewRow.setBackgroundResource(colors[1]); } else { viewRow.setBackgroundResource(colors[0]); } } if (viewListener != null) { viewRow = viewListener.listViewOnCreateListener(position, viewRow, this.rows.get(position)); } return viewRow; }
From source file:org.jfree.data.time.MinuteTest.java
/** * Some checks for the getStart() method. *///from ww w . j a va 2 s .c om @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0); cal.set(Calendar.MILLISECOND, 0); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.jfree.data.time.QuarterTest.java
/** * Some checks for the getLastMillisecond() method. *//*w w w . j a va 2 s. co m*/ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(23583599999L, q.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:StringUtils.java
/** * Converts a long timestamp to a string in the following format:</br> * hh[timeSeparator]mm[timeSeparator]ss * * @param timeStamp/*from w w w .ja v a 2 s . c o m*/ * @param timeSeparator * @return A String containing the formatted timestamp */ static public String formatTime(long timeStamp, String timeSeparator) { if (timeSeparator == null) timeSeparator = ""; Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getDefault()); //use system time zone cal.setTime(new Date(timeStamp)); //set the time //Format the string: StringBuffer bff = new StringBuffer(); // Time (hh[timeSeparator]mm[timeSeparator]ss) bff.append( StringUtils.padWithLeadingZeros(String.valueOf(cal.get(Calendar.HOUR_OF_DAY)), 2) + timeSeparator); bff.append(StringUtils.padWithLeadingZeros(String.valueOf(cal.get(Calendar.MINUTE)), 2) + timeSeparator); bff.append(StringUtils.padWithLeadingZeros(String.valueOf(cal.get(Calendar.SECOND)), 2)); //return the result return bff.toString(); }
From source file:info.magnolia.templating.jsp.taglib.BaseImageTag.java
/** * Create a new imageNode with the image in it. The node is saved under a node that groups all image nodes, whose * name is set to the value of the attribute imageContentNodeName. The name of the node will be set to a name that * is unique for the image. The property that stores the image will be set to the value of * PROPERTIES_FILENAME_VALUE. A sub-node is also created that stores the image properties. * @param imageFile the file/* www. jav a 2 s . co m*/ * @param imageNode The node that will contain the text images. */ protected void createImageNode(File imageFile, Content imageNode) throws PathNotFoundException, AccessDeniedException, RepositoryException, FileNotFoundException, IOException { // Create and save the image data NodeData data; data = imageNode.getNodeData(getFilename()); if (!data.isExist()) { data = imageNode.createNodeData(getFilename(), PropertyType.BINARY); } InputStream iis = new FileInputStream(imageFile); data.setValue(iis); IOUtils.closeQuietly(iis); data.setAttribute(FileProperties.PROPERTY_FILENAME, getFilename()); data.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, PROPERTIES_CONTENTTYPE_VALUE); Calendar value = new GregorianCalendar(TimeZone.getDefault()); data.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, value); data.setAttribute(FileProperties.PROPERTY_SIZE, Long.toString(imageFile.length())); data.setAttribute(FileProperties.PROPERTY_EXTENSION, PROPERTIES_EXTENSION_VALUE); InputStream raf = null; try { ImageInfo ii = new ImageInfo(); raf = new FileInputStream(imageFile); ii.setInput(raf); if (ii.check()) { data.setAttribute(FileProperties.PROPERTY_WIDTH, Long.toString(ii.getWidth())); data.setAttribute(FileProperties.PROPERTY_HEIGHT, Long.toString(ii.getHeight())); } } catch (FileNotFoundException e) { log.error("FileNotFoundException caught when parsing {}, image data will not be available", imageFile.getAbsolutePath()); } finally { IOUtils.closeQuietly(raf); } // delete the temporary file imageFile.delete(); // update modification date and save the new image node NodeTypes.LastModified.update(imageNode.getJCRNode()); imageNode.getParent().save(); }
From source file:ch.algotrader.adapter.fix.DefaultFixAdapter.java
/** * creates an Logon/Logoff statements for fix sessions with weekly logon/logoff defined *///www . ja v a 2 s. co m private void createLogonLogoutStatement(final SessionID sessionId) throws ConfigError, FieldConvertError { if (this.socketInitiator.getSettings().isSetting(sessionId, "LogonPattern") && this.socketInitiator.getSettings().isSetting(sessionId, "LogoutPattern")) { // TimeZone offset String timeZone = this.socketInitiator.getSettings().getString(sessionId, "TimeZone"); int hourOffset = (TimeZone.getDefault().getOffset(System.currentTimeMillis()) - TimeZone.getTimeZone(timeZone).getOffset(System.currentTimeMillis())) / 3600000; // logon String[] logonPattern = this.socketInitiator.getSettings().getString(sessionId, "LogonPattern") .split("\\W"); int logonDay = Integer.valueOf(logonPattern[0]); int logonHour = Integer.valueOf(logonPattern[1]) + hourOffset; int logonMinute = Integer.valueOf(logonPattern[2]); int logonSecond = Integer.valueOf(logonPattern[3]); if (logonHour >= 24) { logonHour -= 24; logonDay += 1; } this.eventScheduler.scheduleLogon(sessionId, new EventPattern(logonDay, logonHour, logonMinute, logonSecond)); // logout String[] logoutPattern = this.socketInitiator.getSettings().getString(sessionId, "LogoutPattern") .split("\\W"); int logoutDay = Integer.valueOf(logoutPattern[0]); int logoutHour = Integer.valueOf(logoutPattern[1]) + hourOffset; int logoutMinute = Integer.valueOf(logoutPattern[2]); int logoutSecond = Integer.valueOf(logoutPattern[3]); if (logoutHour >= 24) { logoutHour -= 24; logoutDay += 1; } this.eventScheduler.scheduleLogout(sessionId, new EventPattern(logoutDay, logoutHour, logoutMinute, logoutSecond)); } }
From source file:com.collabnet.ccf.pi.qc.v90.QCDefect.java
/** * Constructs the GenericArtifact Java object for the defect after getting * the schema from getSchemaAttachment method It also populates all the * values into the defect artifact./* w w w . j a v a 2s . com*/ * * The logic for including attachment fields have been DEPRECATED and not * used. This piece of the code, however, has not been removed since it * might be needed in future if there are any changes with respect to making * attachments as first class citizens. * * @param qcc * @param actionId * @param entityId * @param attachmentNames * (DEPRECATED) * @param isResync * @param lastModifiedBy * @return GenericArtifact Containing all the field values. */ public GenericArtifact getGenericArtifactObject(IConnection qcc, String actionId, String entityId, int commentDescriber, int commentQualifier, List<String> attachmentNames, String syncInfoTransactionId, String connectorUser, String resyncUser, QCHandler defectHandler, String sourceSystemTimezone, String lastModifiedBy) { genericArtifact = QCConfigHelper.getSchemaFieldsForDefect(qcc); List<GenericArtifactField> allFields = genericArtifact.getAllGenericArtifactFields(); int noOfFields = allFields.size(); for (int cnt = 0; cnt < noOfFields; cnt++) { GenericArtifactField thisField = allFields.get(cnt); thisField.setFieldValueHasChanged(true); GenericArtifactField.FieldValueTypeValue thisFieldsDatatype = thisField.getFieldValueType(); String fieldName = thisField.getFieldName(); boolean isJoinedField = QCConfigHelper.isJoinedField(qcc, true, fieldName); if (isJoinedField) { // Assume the 'Name' property is what is wanted from these // referenced objects. Could maybe introduce something like // QCConfigHelper.mapJoinedFieldIdToDisplay() to do this, but it // looks like there's no way to map from OTA property names to // DB column names. In any case Bugs have only 4 reference props // and they all have a Name attribute, so the assumption is safe. // set the referenced ID number as this field's value. Integer thisFieldVal = getReferencedFieldAsInt(fieldName, "ID"); thisField.setFieldValue(thisFieldVal); /* * since joined fields map to an (integer) ID, but customers * might be interested in the string value of the mapped field, * we add a synthetic field to the genericArtifact, reflecting * the attributes contained in this field. This field is of type * STRING and has _HUMAN_READABLE appended to its name. */ String syntheticFieldName = thisField.getFieldName() + QCConfigHelper.HUMAN_READABLE_SUFFIX; String syntheticFieldValue = getReferencedFieldAsString(fieldName, "Name"); GenericArtifactField syntheticField = genericArtifact.addNewField(syntheticFieldName, GenericArtifactField.VALUE_FIELD_TYPE_FLEX_FIELD); syntheticField.setAlternativeFieldName(syntheticFieldName); syntheticField.setFieldValue(syntheticFieldValue); syntheticField.setFieldValueType(FieldValueTypeValue.STRING); // copy over the other attributes. syntheticField.setFieldAction(thisField.getFieldAction()); syntheticField.setFieldValueHasChanged(thisField.getFieldValueHasChanged()); syntheticField.setMaxOccurs(thisField.getMaxOccurs()); syntheticField.setMaxOccursValue(thisField.getMaxOccursValue()); syntheticField.setMinOccurs(thisField.getMinOccurs()); syntheticField.setMinOccursValue(thisField.getMinOccursValue()); syntheticField.setNullValueSupported(thisField.getNullValueSupported()); } else if (thisFieldsDatatype.equals(GenericArtifactField.FieldValueTypeValue.DATE) || thisFieldsDatatype.equals(GenericArtifactField.FieldValueTypeValue.DATETIME)) { String connectorSystemTimeZone = TimeZone.getDefault().getID(); Date dateValue = getFieldAsDate(thisField.getFieldName()); if (dateValue != null) { if (DateUtil.isAbsoluteDateInTimezone(dateValue, connectorSystemTimeZone)) { dateValue = DateUtil.convertToGMTAbsoluteDate(dateValue, connectorSystemTimeZone); thisField.setFieldValueType(GenericArtifactField.FieldValueTypeValue.DATE); thisField.setFieldValue(dateValue); } else { thisField.setFieldValueType(GenericArtifactField.FieldValueTypeValue.DATETIME); thisField.setFieldValue(dateValue); } } } else if (thisFieldsDatatype.equals(GenericArtifactField.FieldValueTypeValue.INTEGER)) { thisField.setFieldValue(getFieldAsInt(thisField.getFieldName())); } else if (thisFieldsDatatype.equals(GenericArtifactField.FieldValueTypeValue.HTMLSTRING)) { thisField.setFieldValue(getFieldAsString(thisField.getFieldName())); } else if (thisFieldsDatatype.equals(GenericArtifactField.FieldValueTypeValue.USER)) { // INFO Changes for user attributes handling... String fieldValue = getFieldAsString(thisField.getFieldName()); if (StringUtils.isEmpty(fieldValue) || fieldValue == null) { thisField.setFieldValue(null); } else { StringTokenizer st = new StringTokenizer(fieldValue, ";"); boolean firstFieldValue = true; while (st.hasMoreTokens()) { String thisFieldValue = st.nextToken(); if (firstFieldValue) { firstFieldValue = false; thisField.setFieldValue(thisFieldValue); } else { if (!StringUtils.isEmpty(thisFieldValue)) { GenericArtifactField field = genericArtifact.addNewField(thisField.getFieldName(), GenericArtifactField.VALUE_FIELD_TYPE_FLEX_FIELD); field.setFieldValueType(GenericArtifactField.FieldValueTypeValue.USER); field.setAlternativeFieldName(thisField.getAlternativeFieldName()); field.setFieldValue(thisFieldValue); } } } } } else if (thisFieldsDatatype.equals(GenericArtifactField.FieldValueTypeValue.BASE64STRING)) { thisField.setFieldValue(getFieldAsInt(thisField.getFieldName())); } else if (thisFieldsDatatype.equals(GenericArtifactField.FieldValueTypeValue.STRING)) { if (thisField.getMaxOccurs() == GenericArtifactField.CARDINALITY_UNBOUNDED) { String fieldValue = getFieldAsString(thisField.getFieldName()); List<String> fieldValues = new ArrayList<String>(); int size = 0; if (fieldValue != null) { fieldValues = getFieldValues(fieldValue); size = fieldValues.size(); } if (size >= 1) thisField.setFieldValue(fieldValues.get(0)); for (int sizeCnt = 1; sizeCnt < size; sizeCnt++) { GenericArtifactField field; field = genericArtifact.addNewField(thisField.getFieldName(), GenericArtifactField.VALUE_FIELD_TYPE_FLEX_FIELD); field.setFieldValueType(GenericArtifactField.FieldValueTypeValue.STRING); field.setFieldValue(fieldValues.get(sizeCnt)); field.setAlternativeFieldName(thisField.getAlternativeFieldName()); } } else { String fieldValueAsString = null; if (fieldName.equals("BG_VTS")) { Date dateFieldValue = getFieldAsDate(fieldName); thisField.setFieldValue(dateFieldValue); // thisField.setFieldValue(DateUtil.formatQCDate(dateFieldValue)); thisField.setFieldValueType(GenericArtifactField.FieldValueTypeValue.DATETIME); } else { fieldValueAsString = getFieldAsString(fieldName); thisField.setFieldValue(fieldValueAsString); } } } } // If this is a resync request do not ship comments IRecordSet auditPropertiesRS = null; String deltaComment = ""; try { List<String> txnIds = defectHandler.getTransactionIdsInRangeForDefects(qcc, Integer.parseInt(entityId), Integer.parseInt(syncInfoTransactionId), Integer.parseInt(actionId), connectorUser, resyncUser); if (!txnIds.isEmpty()) { auditPropertiesRS = defectHandler.getAuditPropertiesRecordSet(qcc, txnIds); deltaComment = defectHandler.getDeltaOfCommentForDefects(auditPropertiesRS, qcc); } } finally { if (auditPropertiesRS != null) { auditPropertiesRS.safeRelease(); } } genericArtifact.getAllGenericArtifactFieldsWithSameFieldName(QCConfigHelper.QC_BG_DEV_COMMENTS).get(0) .setFieldValue(deltaComment); // add last modified user as a mappable field GenericArtifactField field; field = genericArtifact.addNewField(QCConfigHelper.lastModifiedUserFieldName, GenericArtifactField.VALUE_FIELD_TYPE_FLEX_FIELD); field.setFieldValueType(GenericArtifactField.FieldValueTypeValue.STRING); field.setFieldAction(FieldActionValue.REPLACE); field.setFieldValue(lastModifiedBy); return genericArtifact; }