List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Format./*from ww w .j a v a2 s. co m*/ * @param date the date * @param pattern the pattern * @return the string */ public static String format(Date date, String pattern) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); String strDate = fmt.print(new DateTime(date)); LOGGER.debug("Timestamp " + strDate); return strDate; }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the time zone diff./*from w w w . j a v a2 s. c o m*/ * @param timeZone the time zone * @return the time zone diff */ public static String getTimeZoneDiff(String timeZone) { DateTime startDate = new DateTime(DateTimeZone.forID(timeZone)); DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL_TZ); String timeval = fmt.print(startDate); int lastIndexOfSpace = timeval.lastIndexOf(" "); timeval = timeval.substring(lastIndexOfSpace + 1, timeval.length()); return timeval; }
From source file:com.edoli.calendarlms.CalendarPagerView.java
License:Apache License
public void setCurrentCalendar(DateTime date) { mDate = date;/*w w w. j a va 2 s . c o m*/ mCalendarView.setDate(date); mCurrentCalendarView = new CalendarContentView(getContext()); mCurrentCalendarView.setDate(date); mCurrentCalendarView.setCalendarListener(mCalendarListener); DateTimeFormatter formatter = DateTimeFormat.forPattern("MMMMMMM yyyy"); formatter = formatter.withLocale(Locale.ENGLISH); String strDate = formatter.print(date); mCalendarView.setTitle(strDate); mCalendarView.onCalendarChanged(date); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); addView(mCurrentCalendarView, params); }
From source file:com.edoli.calendarlms.DayOfWeekAdapter.java
License:Apache License
@SuppressWarnings("deprecation") @Override/*from ww w . j a v a 2 s. c o m*/ public View getView(int position, View convertView, ViewGroup parent) { Context context = parent.getContext(); RelativeLayout view = new RelativeLayout(context); AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, mHeight); view.setLayoutParams(layoutParams); TextView dayView = new TextView(context); RelativeLayout.LayoutParams dayParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); dayParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); dayParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); dayView.setLayoutParams(dayParams); DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE"); dayView.setText(formatter.print(mDate.plusDays(position))); view.addView(dayView); // Set Color dayView.setTextColor(mTextColors[position]); view.setBackgroundDrawable(mBackground); return view; }
From source file:com.effektif.workflow.impl.data.types.DateTypeImpl.java
License:Apache License
@Override public String convertInternalToText(Object value, Hints hints) { DateTimeFormatter textFormatter = DateTimeFormat.longDate().withLocale(getLocale()); return value != null ? textFormatter.print((ReadablePartial) value) : null; }
From source file:com.einzig.ipst2.adapters.ListItemAdapter_PS.java
License:Open Source License
public View getView(int position, View convertView, ViewGroup parent) { final PortalSubmission item = this.shownItems.get(position); @SuppressLint("ViewHolder") LinearLayout itemLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.row_pslist, parent, false);/*from w w w . j a va 2 s .com*/ ImageView iconView = (ImageView) itemLayout.findViewById(R.id.status_icon); if (iconView != null) { if (item instanceof PortalAccepted) { iconView.setImageDrawable(AppCompatDrawableManager.get().getDrawable(context, R.drawable.ic_check)); iconView.setBackgroundColor(context.getResources().getColor(R.color.accepted)); } else if (item instanceof PortalRejected) { iconView.setImageDrawable( AppCompatDrawableManager.get().getDrawable(context, R.drawable.ic_rejected)); iconView.setBackgroundColor(context.getResources().getColor(R.color.rejected)); } else { iconView.setImageDrawable( AppCompatDrawableManager.get().getDrawable(context, R.drawable.ic_pending)); } } TextView pstimelabel = (TextView) itemLayout.findViewById(R.id.psdate_rowpslist); if (pstimelabel != null) { DateTimeFormatter formatter = new PreferencesHelper(context).getUIFormatter(); pstimelabel.setText( formatter.print(item.getDateSubmitted()) + " - " + item.getDaysSinceResponse() + " day(s) ago"); } TextView psnamelabel = (TextView) itemLayout.findViewById(R.id.psname_rowpslist); if (psnamelabel != null) psnamelabel.setText(item.getName()); return itemLayout; }
From source file:com.einzig.ipst2.util.AsyncLogger.java
License:Open Source License
/** * Get the name of the file to write logs to * * @return name of the file to write logs to *///from w w w . j a va 2 s . c o m private String getFilename() { DateTimeFormatter formatter = ISODateTimeFormat.basicDate(); return "IPST_Logs_" + formatter.print(LocalDateTime.now()) + ".txt"; }
From source file:com.einzig.ipst2.util.CSVExportHelper.java
License:Open Source License
protected String doInBackground(String... urls) { DateTimeFormatter uiFormatter = helper.getUIFormatter(); DateTimeFormatter fileFormatter = ISODateTimeFormat.basicDate(); String date = fileFormatter.print(LocalDateTime.now()); String fileName = "/IPST2-backup-" + exportType + "-" + date + ".csv"; File root = Environment.getExternalStorageDirectory(); File dir = new File(root.getAbsolutePath() + "/Download"); File file = new File(dir, fileName); if (Environment.getExternalStorageDirectory() == null) { errorHappened = true;// ww w . j av a 2s . c om errorThatHappened = "No SD Card Found"; } else { try { Logger.d(file.getAbsolutePath()); CSVWriter mWriter = new CSVWriter(new FileWriter(file)); Vector<? extends PortalSubmission> subList = db.getAllPortals(helper.isSeerOnly()); SortHelper.sortList(subList, activity); String[] mExportChartHeaders = { "Portal Name", "Date Submitted", "Date Accepted", "Date Rejected", "Status", "Live Address", "Intel Link URL", "Picture URL", "Rejection Reason", "Lat/Lon", "Date Pattern" }; mWriter.writeNext(mExportChartHeaders); for (PortalSubmission submission : subList) { Logger.d("PORTAL SUBMISSION ADDED TO CSV: " + submission.getName()); String name = submission.getName(); String dateSubmitted = "N/A"; if (submission.getDateSubmitted() != null) dateSubmitted = uiFormatter.print(submission.getDateSubmitted()); String dateAccepted = "N/A"; String dateRejected = "N/A"; if (submission instanceof PortalAccepted || submission instanceof PortalRejected) { if (((PortalResponded) submission).getDateResponded() != null) { if (submission instanceof PortalAccepted) dateAccepted = uiFormatter.print(((PortalResponded) submission).getDateResponded()); else dateRejected = uiFormatter.print(((PortalResponded) submission).getDateResponded()); } } String status = "Pending"; if (submission instanceof PortalAccepted) status = "Accepted"; else if (submission instanceof PortalRejected) status = "Rejected"; String liveAddress = "N/A"; String intelLink = "N/A"; String pictureURL = "N/A"; String rejectionReason = "N/A"; String latLonString = "N/A"; if (submission.getPictureURL() != null) pictureURL = submission.getPictureURL(); if (submission instanceof PortalResponded) { if (submission instanceof PortalAccepted) { liveAddress = ((PortalAccepted) submission).getLiveAddress(); intelLink = ((PortalAccepted) submission).getIntelLinkURL(); try { latLonString = intelLink.substring(intelLink.indexOf("=") + 1, intelLink.indexOf("&")); } catch (java.lang.StringIndexOutOfBoundsException e) { latLonString = "String Index was Out of Bounds"; } } else if (submission instanceof PortalRejected) { rejectionReason = ((PortalRejected) submission).getRejectionReason(); } } if (name != null) name = name.replaceAll(",", ""); status = status.replaceAll(",", ""); if (liveAddress != null) { liveAddress = liveAddress.replaceAll(",", ""); } if (intelLink != null) intelLink = intelLink.replaceAll(",", ","); if (rejectionReason != null) rejectionReason = rejectionReason.replaceAll(",", ""); String[] lineOfCSV = { name, dateSubmitted, dateAccepted, dateRejected, status, liveAddress, intelLink, pictureURL, rejectionReason, latLonString, helper.getUIFormatterPattern() }; if (exportType.equalsIgnoreCase("all")) mWriter.writeNext(lineOfCSV); else if (exportType.equalsIgnoreCase("accepted")) if (status.equalsIgnoreCase("Accepted")) mWriter.writeNext(lineOfCSV); } mWriter.close(); pathTofile = file.getAbsolutePath(); //Intent sendIntent = new Intent(Intent.ACTION_SEND); //sendIntent.setType("application/csv"); //sendIntent.putExtra(Intent.EXTRA_STREAM, u1); //startActivity(sendIntent); } catch (Exception e) { e.printStackTrace(); errorThatHappened = e.toString(); errorHappened = true; } db.close(); } return ""; }
From source file:com.emo.ananas.configs.EmailConfig.java
License:Apache License
public EmailConfig(final Config config) { Preconditions.checkArgument(config.hasPath("to"), "report must have a report.to defined"); Preconditions.checkArgument(config.getStringList("to").size() >= 1, "report must have at least one recipient as an array in report.to"); Preconditions.checkArgument(config.hasPath("from"), "report must have a sender in report.from"); Preconditions.checkArgument(config.hasPath("subject"), "report must have a subject, it can contain a date format as defined by JodaTime"); final String rawSubject = config.getString("subject"); final Pattern pattern = Pattern.compile("\\%d\\{([^\\}]+)\\}"); final Matcher matcher = pattern.matcher(rawSubject); final DateTime dt = new DateTime(); final StringBuffer sb = new StringBuffer(); while (matcher.find()) { final String datePattern = matcher.group(1); final DateTimeFormatter fmt = DateTimeFormat.forPattern(datePattern); final String formattedDate = fmt.print(dt); matcher.appendReplacement(sb, formattedDate); }/*from ww w . j av a2 s . com*/ matcher.appendTail(sb); this.to = Collections.unmodifiableList(config.getStringList("to")); this.from = config.getString("from"); this.subject = sb.toString(); }
From source file:com.enonic.vertical.adminweb.handlers.ContentBaseHandlerServlet.java
License:Open Source License
public void handlerBrowse(HttpServletRequest request, HttpServletResponse response, HttpSession session, AdminService admin, ExtendedMap formItems, ExtendedMap parameters, User oldUser, Document verticalDoc) throws VerticalAdminException { UserEntity user = securityService.getUser(oldUser); String op = formItems.getString("op"); String subop = formItems.getString("subop", "browse"); String contenthandler = formItems.getString("contenthandler", ""); int submittetCategoryKey = formItems.getInt("categorykey", -1); if (submittetCategoryKey == -1) { submittetCategoryKey = formItems.getInt("cat", -1); }//w w w . j a va2s .c om CategoryKey categoryKey = CategoryKey.parse(submittetCategoryKey); boolean categoryDisabled_which_means_user_do_not_have_read_access = formItems.getBoolean("disabled", false); String[] contentTypeStringArray = formItems.getStringArray("contenttypestring"); int[] contentTypes = resolveContentTypes(contentTypeStringArray); StringBuffer contentTypesString = createContentTypesString(contentTypes); if (!"browse".equals(subop)) { String deploymentPath = DeploymentPathResolver.getAdminDeploymentPath(request); CookieUtil.setCookie(response, getPopupCookieName(contentTypesString.toString()), categoryKey != null ? categoryKey.toString() : "-1", COOKIE_TIMEOUT, deploymentPath); } ContentTypeKey contentTypeKey = null; boolean hasAdminReadOnCategory = true; boolean hasCategoryRead = false; boolean hasCategoryCreate = false; boolean hasCategoryPublish = false; boolean hasCategoryAdministrate = false; CategoryAccessResolver categoryAccessResolver = new CategoryAccessResolver(groupDao); if (categoryKey != null) { CategoryEntity category = categoryDao.findByKey(categoryKey); hasAdminReadOnCategory = categoryAccessResolver.hasAdminBrowseCategoryAccess(user, category); hasCategoryRead = categoryAccessResolver.hasReadCategoryAccess(user, category); hasCategoryCreate = categoryAccessResolver.hasCreateContentAccess(user, category); hasCategoryPublish = categoryAccessResolver.hasApproveContentAccess(user, category); hasCategoryAdministrate = categoryAccessResolver.hasAdministrateCategoryAccess(user, category); ContentTypeEntity contentType = category.getContentType(); if (contentType != null) { contentTypeKey = contentType.getContentTypeKey(); } } String sortBy = formItems.getString("sortby", "@timestamp"); String sortByDirection = formItems.getString("sortby-direction", "DESC"); StringBuffer orderBy = new StringBuffer(); orderBy.append(sortBy); orderBy.append(" "); orderBy.append(sortByDirection); final String cookieName = "archiveBrowseItemsPerPage"; int index = formItems.getInt("index", 0); int count = ListCountResolver.resolveCount(request, formItems, cookieName); CookieUtil.setCookie(response, cookieName, Integer.toString(count), COOKIE_TIMEOUT, DeploymentPathResolver.getAdminDeploymentPath(request)); XMLDocument xmlContent = null; String searchType = formItems.getString("searchtype", null); // Get contents if (searchType != null) { if (searchType.equals("simple")) { xmlContent = new SearchUtility(userDao, groupDao, securityService, contentService).simpleSearch( oldUser, formItems, categoryKey, contentTypes, orderBy.toString(), index, count); parameters.put("searchtext", formItems.getString("searchtext", "")); parameters.put("scope", formItems.getString("scope")); } else { String ownerGroupKey = formItems.getString("owner", ""); if (!"".equals(ownerGroupKey)) { User ownerUser = getUserFromUserGroupKey(ownerGroupKey); parameters.put("owner.uid", ownerUser.getName()); parameters.put("owner.fullName", ownerUser.getDisplayName()); parameters.put("owner.qualifiedName", ownerUser.getQualifiedName()); addUserKeyToFormItems(formItems, "owner.key", ownerUser); } String modifierGroupKey = formItems.getString("modifier", ""); if (!"".equals(modifierGroupKey)) { User modifierUser = getUserFromUserGroupKey(modifierGroupKey); parameters.put("modifier.uid", modifierUser.getName()); parameters.put("modifier.fullName", modifierUser.getDisplayName()); parameters.put("modifier.qualifiedName", modifierUser.getQualifiedName()); addUserKeyToFormItems(formItems, "modifier.key", modifierUser); } String assignee = formItems.getString("_assignee", ""); if (!"".equals(assignee)) { User assigneeUser = getUserFromUserKey(assignee); if (assigneeUser == null) { assigneeUser = getUserFromUserGroupKey(assignee); } parameters.put("assignment.assigneeUserKey", assignee); parameters.put("assignment.assigneeDisplayName", assigneeUser.getDisplayName()); parameters.put("assignment.assigneeQualifiedName", assigneeUser.getQualifiedName().toString()); } String assigner = formItems.getString("_assigner", ""); if (!"".equals(assigner)) { User assignerUser = getUserFromUserKey(assigner); if (assignerUser == null) { assignerUser = getUserFromUserGroupKey(assigner); } parameters.put("assignment.assignerUserKey", assigner); parameters.put("assignment.assignerDisplayName", assignerUser.getDisplayName()); parameters.put("assignment.assignerQualifiedName", assignerUser.getQualifiedName().toString()); } String assignmentDueDate = formItems.getString("date_assignmentDueDate", ""); if (!"".equals(assignmentDueDate)) { DateTimeFormatter norwegianDateFormatter = DateTimeFormat.forPattern("dd.MM.yyyy"); DateMidnight assignmentDueDateAsDateTime = norwegianDateFormatter .parseDateTime(assignmentDueDate).toDateMidnight(); DateTimeFormatter isoDateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); String assignmentDueDateAsStringIsoFormatted = isoDateFormatter .print(assignmentDueDateAsDateTime); parameters.put("assignment.dueDate", assignmentDueDateAsStringIsoFormatted); parameters.put("assignment.dueDate.op", formItems.getString("_assignmentDueDate.op", "")); } xmlContent = new SearchUtility(userDao, groupDao, securityService, contentService) .advancedSearch(oldUser, formItems, contentTypes, orderBy.toString(), index, count); parameters.put("asearchtext", formItems.getString("asearchtext", "")); parameters.put("ascope", formItems.getString("ascope")); parameters.put("subcategories", formItems.getString("subcategories")); parameters.put("state", formItems.getString("state", "")); parameters.put("owner", ownerGroupKey); parameters.put("modifier", modifierGroupKey); parameters.put("created.op", formItems.getString("created.op", "")); parameters.put("created", formItems.getString("datecreated", "")); parameters.put("modified.op", formItems.getString("modified.op", "")); parameters.put("modified", formItems.getString("datemodified", "")); parameters.put("acontentkey", formItems.getString("acontentkey", "")); parameters.put("filter", formItems.getString("filter", "")); parameters.put("selectedtabpage", formItems.getString("selectedtabpage", "")); parameters.put("duedate", assignmentDueDate); } parameters.put("searchtype", searchType); } else if (hasAdminReadOnCategory) { xmlContent = admin.getContent(oldUser, categoryKey, false, orderBy.toString(), index, count, 0, 0, 0); } if (xmlContent != null) { Document contentDoc = xmlContent.getAsDOMDocument(); XMLTool.mergeDocuments(verticalDoc, contentDoc, true); // Find all content types and categories in this list Element[] contentElems = XMLTool.getElements(contentDoc.getDocumentElement(), "content"); Set<ContentTypeKey> contentTypeKeys = new HashSet<ContentTypeKey>(); Set<Integer> categoryKeys = new HashSet<Integer>(); for (Element contentElem : contentElems) { contentTypeKeys.add(new ContentTypeKey(contentElem.getAttribute("contenttypekey"))); Element categoryElem = XMLTool.getElement(contentElem, "categoryname"); categoryKeys.add(Integer.parseInt(categoryElem.getAttribute("key"))); } if (contentTypeKeys.size() == 0 && searchType == null && contentTypeKey != null) { // This is a normal listing of an empty category contentTypeKeys.add(contentTypeKey); } if (contentTypeKeys.size() > 0) { XMLDocument ctyDoc = admin.getContentTypes(ContentTypeKey.convertToIntArray(contentTypeKeys), true); XMLTool.mergeDocuments(verticalDoc, ctyDoc.getAsDOMDocument(), true); } // Get content types for this site XMLDocument siteContentTypesDoc = admin.getContentTypes(false); final Document siteContentTypesDocument = siteContentTypesDoc.getAsDOMDocument(); XMLTool.renameElement(siteContentTypesDocument.getDocumentElement(), "sitecontenttypes"); XMLTool.mergeDocuments(verticalDoc, siteContentTypesDocument, true); // Get all categories if (categoryKeys.size() > 0) { Integer[] keyArray = new Integer[categoryKeys.size()]; keyArray = categoryKeys.toArray(keyArray); CategoryCriteria categoryCriteria = new CategoryCriteria(); categoryCriteria.addCategoryKeys(Arrays.asList(keyArray)); Document categoriesDoc = admin.getMenu(oldUser, categoryCriteria).getAsDOMDocument(); XMLTool.mergeDocuments(verticalDoc, categoriesDoc, false); } } Document headerDoc = admin.getCategoryPathXML(categoryKey, contentTypes).getAsDOMDocument(); XMLTool.mergeDocuments(verticalDoc, headerDoc, true); // Default browse config Document defaultBrowseConfig = AdminStore.getXml(session, "defaultbrowseconfig.xml").getAsDOMDocument(); XMLTool.mergeDocuments(verticalDoc, defaultBrowseConfig, true); // Feedback if (formItems.containsKey("feedback")) { addFeedback(verticalDoc, formItems.getInt("feedback")); } // Category header if (categoryKey != null) { // Category // Small hack: we put the current category on /data/category, all categories // used are also present in /data/categories/category, but without contentcount and accessrights Document categoryDoc = admin.getCategory(oldUser, categoryKey.toInt()).getAsDOMDocument(); XMLTool.mergeDocuments(verticalDoc, categoryDoc, false); int superCategoryKey = admin.getSuperCategoryKey(categoryKey.toInt()); if (superCategoryKey != -1) { CategoryAccessRight supercar = admin.getCategoryAccessRight(oldUser, superCategoryKey); parameters.put("parentcategoryadministrate", supercar.getAdministrate()); } // Trenger indexparametre for vite hvilke felt det kan sorteres p.. list.xsl Document indexingDoc = XMLTool.domparse(admin.getIndexingParametersXML(contentTypeKey)); XMLTool.mergeDocuments(verticalDoc, indexingDoc, true); parameters.put("cat", categoryKey.toString()); parameters.put("contenttypekey", Integer.toString(contentTypeKey != null ? contentTypeKey.toInt() : -1)); parameters.put("selectedunitkey", Integer.toString(admin.getUnitKey(categoryKey.toInt()))); } else { parameters.putInt("cat", -1); parameters.putInt("selectedunitkey", -1); } if (categoryDisabled_which_means_user_do_not_have_read_access) { parameters.put("searchonly", "true"); } parameters.put("index", index); parameters.put("count", count); parameters.put("op", op); parameters.put("subop", subop); parameters.put("hasAdminBrowse", hasAdminReadOnCategory); parameters.put("hasCategoryRead", hasCategoryRead); parameters.put("hasCategoryCreate", hasCategoryCreate); parameters.put("hasCategoryPublish", hasCategoryPublish); parameters.put("hasCategoryAdministrate", hasCategoryAdministrate); parameters.put("fieldname", formItems.getString("fieldname", "")); parameters.put("fieldrow", formItems.getString("fieldrow", "")); parameters.put("contenttypestring", contentTypesString.toString()); parameters.put("sortby", sortBy); parameters.put("sortby-direction", sortByDirection); parameters.put("contenthandler", contenthandler); parameters.put("minoccurrence", formItems.getString("minoccurrence", "")); parameters.put("maxoccurrence", formItems.getString("maxoccurrence", "")); if (formItems.containsKey("reload")) { parameters.put("reload", formItems.getString("reload")); } addPageTemplatesOfUserSitesToDocument(admin, user, PageTemplateType.CONTENT, verticalDoc); transformXML(request, response, verticalDoc, "content_list.xsl", parameters); }