List of usage examples for org.apache.commons.lang.time DateFormatUtils format
public static String format(Date date, String pattern, Locale locale)
Formats a date/time into a specific pattern in a locale.
From source file:org.jtalks.jcommune.web.controller.ImageUploadController.java
/** * Sets up avatar cache related headers. * * @param response - HTTP response object where set headers * @param avatarLastModificationTime - last modification time of avatar *///from w w w . j a v a 2 s . c o m protected void setupAvatarHeaders(HttpServletResponse response, Date avatarLastModificationTime) { response.setHeader("Pragma", "public"); response.setDateHeader("Expires", System.currentTimeMillis() + AVATAR_CACHE_AGE_SEC * 1000); response.setHeader("Cache-Control", "public"); response.addHeader("Cache-Control", "max-age=" + AVATAR_CACHE_AGE_SEC); String formattedDateLastModified = DateFormatUtils.format(avatarLastModificationTime, HTTP_HEADER_DATETIME_PATTERN, Locale.US); response.setHeader("Last-Modified", formattedDateLastModified); }
From source file:org.jtalks.jcommune.web.controller.ImageUploadControllerTest.java
@Test public void testGetIfModifiedSinceDate() { long currentMillis = System.currentTimeMillis(); long currentTimeIgnoreMillis = (currentMillis / 1000) * 1000; Date date = new Date(currentTimeIgnoreMillis); String dateAsString = DateFormatUtils.format(date, ImageUploadController.HTTP_HEADER_DATETIME_PATTERN, Locale.US);/*w w w . j a v a 2 s . c om*/ Date result = imageUploadController.getIfModifiedSinceDate(dateAsString); assertEquals(result.getTime(), date.getTime()); }
From source file:org.linagora.linshare.view.tapestry.components.SignatureDetailsDisplayer.java
public String getUserOwnsignatureDate() { if (userOwnsignature != null) { String pattern = messages.get("global.pattern.timestamp"); return DateFormatUtils.format(userOwnsignature.getCreationDate().getTime(), pattern, persistentLocale.get()); } else/* w ww . ja v a 2 s . c o m*/ return null; }
From source file:org.linagora.linshare.view.tapestry.components.SignatureDetailsDisplayer.java
/** * Format the creation date for good displaying using DateFormatUtils of apache commons lib. * @return creation date the date in localized format. *///w ww. j a v a2 s. com public String getCreationDateCustom() { if (signature != null) { String pattern = messages.get("global.pattern.timestamp"); return DateFormatUtils.format(signature.getCreationDate().getTime(), pattern, persistentLocale.get()); } else return null; }
From source file:org.linagora.linshare.view.tapestry.components.SignatureDetailsDisplayer.java
public String getCertValidity() { if (signature != null) { String pattern = messages.get("global.pattern.timestamp"); return DateFormatUtils.format(signature.getCertNotAfter().getTime(), pattern, persistentLocale.get()); } else//from w w w . j a va 2 s. c o m return null; }
From source file:org.linagora.linshare.view.tapestry.pages.signature.SignDocument.java
/** * Format the creation date in the view for good displaying using DateFormatUtils of apache commons lib. * @return creation date the date in localized format. *///from w w w . ja v a 2 s. c om public String getCreateDate() { return DateFormatUtils.format(document.getCreationDate().getTime(), "dd/MM/yyyy", persistentLocale.get()); }
From source file:org.linagora.linshare.view.tapestry.pages.signature.SignDocument.java
/** * Format the signer cert date (not after)in the view for good displaying using DateFormatUtils of apache commons lib. * @return creation date the date in localized format. */// w w w .j a va 2 s .c o m public String getSignerCertNotAfter() { return DateFormatUtils.format(userSignature.getSignercert().getNotAfter().getTime(), "dd/MM/yyyy HH:mm", persistentLocale.get()); }
From source file:org.openmrs.module.coreapps.fragment.controller.visit.VisitDetailsFragmentController.java
public SimpleObject getVisitDetails( @SpringBean("featureToggles") FeatureToggleProperties featureToggleProperties, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @RequestParam("visitId") Visit visit, UiUtils uiUtils, UiSessionContext sessionContext) throws ParseException { SimpleObject simpleObject = SimpleObject.fromObject(visit, uiUtils, "id", "location"); User authenticatedUser = sessionContext.getCurrentUser(); boolean canDelete = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_ENCOUNTER); boolean canEdit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_EDIT_ENCOUNTER); boolean canDeleteVisit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_VISIT); Date startDatetime = visit.getStartDatetime(); Date stopDatetime = visit.getStopDatetime(); simpleObject.put("startDatetime", DateFormatUtils.format(startDatetime, "dd MMM yyyy hh:mm a", Context.getLocale())); if (stopDatetime != null) { simpleObject.put("stopDatetime", DateFormatUtils.format(stopDatetime, "dd MMM yyyy hh:mm a", Context.getLocale())); } else {// w w w . ja v a 2 s . c o m simpleObject.put("stopDatetime", null); } VisitDomainWrapper visitWrapper = new VisitDomainWrapper(visit, emrApiProperties); List<SimpleObject> encounters = new ArrayList<SimpleObject>(); for (Encounter encounter : visitWrapper.getSortedEncounters()) { encounters.add(createEncounterJSON(uiUtils, authenticatedUser, canDelete, canEdit, encounter)); } simpleObject.put("encounters", encounters); simpleObject.put("admitted", visitWrapper.isAdmitted()); simpleObject.put("canDeleteVisit", verifyIfUserHasPermissionToDeleteVisit(visit, authenticatedUser, canDeleteVisit)); return simpleObject; }
From source file:org.openmrs.module.coreapps.fragment.controller.visit.VisitDetailsFragmentController.java
private SimpleObject createEncounterJSON(UiUtils uiUtils, User authenticatedUser, boolean canDelete, boolean canEdit, Encounter encounter) { SimpleObject simpleEncounter = SimpleObject.fromObject(new EncounterDomainWrapper(encounter), uiUtils, "encounterId", "primaryProvider", "location", "encounterDatetime", "encounterProviders.provider", "voided", "form"); // manually set the date and time components so we can control how we format them simpleEncounter.put("encounterDate", DateFormatUtils.format(encounter.getEncounterDatetime(), "dd MMM yyyy", Context.getLocale())); simpleEncounter.put("encounterTime", DateFormatUtils.format(encounter.getEncounterDatetime(), "hh:mm a", Context.getLocale())); EncounterType encounterType = encounter.getEncounterType(); simpleEncounter.put("encounterType", SimpleObject.create("uuid", encounterType.getUuid(), "name", uiUtils.format(encounterType))); if (verifyIfUserHasPermissionToDeleteAnEncounter(encounter, authenticatedUser, canDelete)) { simpleEncounter.put("canDelete", true); }/* w w w .j a va2 s. c o m*/ if (verifyIfUserHasPermissionToEditAnEncounter(encounter, authenticatedUser, canEdit)) { simpleEncounter.put("canEdit", true); } if (encounter.getVisit() != null) { simpleEncounter.put("visitId", encounter.getVisit().getId()); } return simpleEncounter; }
From source file:org.openmrs.module.ebolaexample.fragment.controller.overview.PatientHeaderFragmentController.java
public void controller(FragmentConfiguration config, @FragmentParam(required = false, value = "appContextModel") AppContextModel appContextModel, @FragmentParam("patient") Object patient, @InjectBeans PatientDomainWrapper wrapper, @SpringBean("adtService") AdtService adtService, UiSessionContext sessionContext, FragmentModel model) { if (patient instanceof Patient) { wrapper.setPatient((Patient) patient); config.addAttribute("patient", wrapper); } else {//ww w . j a v a 2 s . c o m wrapper = (PatientDomainWrapper) patient; } VisitDomainWrapper activeVisit = (VisitDomainWrapper) config.getAttribute("activeVisit"); if (activeVisit == null) { try { Location visitLocation = adtService .getLocationThatSupportsVisits(sessionContext.getSessionLocation()); activeVisit = adtService.getActiveVisit(wrapper.getPatient(), visitLocation); } catch (IllegalArgumentException ex) { // location does not support visits } } if (appContextModel == null) { AppContextModel contextModel = sessionContext.generateAppContextModel(); contextModel.put("patient", new PatientContextModel(wrapper.getPatient())); contextModel.put("visit", activeVisit == null ? null : new VisitContextModel(activeVisit)); model.addAttribute("appContextModel", contextModel); } if (activeVisit != null) { config.addAttribute("activeVisit", activeVisit); config.addAttribute("activeVisitStartDatetime", DateFormatUtils.format(activeVisit.getStartDatetime(), "dd MMM yyyy hh:mm a", Context.getLocale())); } List<ExtraPatientIdentifierType> extraPatientIdentifierTypes = new ArrayList<ExtraPatientIdentifierType>(); config.addAttribute("extraPatientIdentifierTypes", extraPatientIdentifierTypes); config.addAttribute("extraPatientIdentifiersMappedByType", wrapper.getExtraIdentifiersMappedByType(sessionContext.getSessionLocation())); config.addAttribute("defaultDashboard", null); PersonAttribute nextOfKinName = wrapper.getPatient().getAttribute(MetadataUtils .existing(PersonAttributeType.class, EbolaMetadata._PersonAttributeType.NEXT_OF_KIN_NAME)); PersonAttribute nextOfKinPhone = wrapper.getPatient().getAttribute(MetadataUtils .existing(PersonAttributeType.class, EbolaMetadata._PersonAttributeType.NEXT_OF_KIN_PHONE)); model.addAttribute("nextOfKinName", nextOfKinName); model.addAttribute("nextOfKinPhone", nextOfKinPhone); }