List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:gobblin.source.extractor.utils.Utils.java
License:Apache License
/** * Helper method for getting a value containing CURRENTDAY-1 or CURRENTHOUR-1 in the form yyyyMMddHHmmss * @param value/*from w ww. ja v a2 s . c o m*/ * @param timezone * @return */ public static long getLongWithCurrentDate(String value, String timezone) { if (Strings.isNullOrEmpty(value)) { return 0; } DateTime time = getCurrentTime(timezone); DateTimeFormatter dtFormatter = DateTimeFormat.forPattern(CURRENT_DATE_FORMAT).withZone(time.getZone()); if (value.toUpperCase().startsWith(CURRENT_DAY)) { return Long.parseLong( dtFormatter.print(time.minusDays(Integer.parseInt(value.substring(CURRENT_DAY.length() + 1))))); } if (value.toUpperCase().startsWith(CURRENT_HOUR)) { return Long.parseLong(dtFormatter .print(time.minusHours(Integer.parseInt(value.substring(CURRENT_HOUR.length() + 1))))); } return Long.parseLong(value); }
From source file:gobblin.source.extractor.utils.Utils.java
License:Apache License
/** * Convert joda time to a string in the given format * @param input timestamp//from www .jav a2 s. c o m * @param format expected format * @param timezone time zone of timestamp * @return string format of timestamp */ public static String dateTimeToString(DateTime input, String format, String timezone) { String tz = StringUtils.defaultString(timezone, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE); DateTimeZone dateTimeZone = getTimeZone(tz); DateTimeFormatter outputDtFormat = DateTimeFormat.forPattern(format).withZone(dateTimeZone); return outputDtFormat.print(input); }
From source file:gobblin.source.PartitionedFileSourceBase.java
License:Apache License
@Override public List<WorkUnit> getWorkunits(SourceState state) { DateTimeFormatter formatter = DateTimeFormat.fullDateTime(); // Initialize all instance variables for this object init(state);/*from ww w .ja v a 2s .co m*/ LOG.info("Will pull data from " + formatter.print(this.lowWaterMark) + " until " + this.maxFilesPerJob + " files have been processed, or until there is no more data to consume"); LOG.info("Creating workunits"); // Weighted MultiWorkUnitWeightedQueue, the job will add new WorkUnits to the queue along with a weight for each // WorkUnit. The queue will take care of balancing the WorkUnits amongst a set number of MultiWorkUnits MultiWorkUnitWeightedQueue multiWorkUnitWeightedQueue = new MultiWorkUnitWeightedQueue( this.maxWorkUnitsPerJob); // Add failed work units from the previous execution addFailedWorkUnits(getPreviousWorkUnitsForRetry(this.sourceState), multiWorkUnitWeightedQueue); // If the file count has not exceeded maxFilesPerJob then start adding new WorkUnits to for this job if (this.fileCount >= this.maxFilesPerJob) { LOG.info( "The number of work units from previous job has already reached the upper limit, no more workunits will be made"); return multiWorkUnitWeightedQueue.getQueueAsList(); } addNewWorkUnits(multiWorkUnitWeightedQueue); return multiWorkUnitWeightedQueue.getQueueAsList(); }
From source file:gov.nih.nci.calims2.ui.report.filledreport.FilledReportController.java
License:BSD License
/** * /*from w ww. jav a2s . c o m*/ * @param response The servlet response. * @param id The id of the filledreport to view. * @param formatName The format of the pdf file. */ @RequestMapping("/exportReport.do") public void exportReport(HttpServletResponse response, @RequestParam("id") Long id, @RequestParam("format") String formatName) { FilledReport filledReport = getMainService().findById(FilledReport.class, id); Report report = filledReport.getReport(); FilledReportFormat format = FilledReportFormat.valueOf(formatName); try { ServletOutputStream servletOutputStream = response.getOutputStream(); File exportedFile = ((FilledReportService) getMainService()).exportJasperReport(id, tempfiledir, format); response.setContentType(format.getContentType()); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd-HHmmss"); String filename = report.getName() + fmt.print(filledReport.getExecutionTime()) + format.getExtention(); response.setHeader("Content-Disposition", "attachment;filename=" + filename); FileInputStream fileInputStream = new FileInputStream(exportedFile); IOUtils.copyLarge(fileInputStream, servletOutputStream); IOUtils.closeQuietly(fileInputStream); servletOutputStream.flush(); servletOutputStream.close(); exportedFile.delete(); } catch (IOException e1) { throw new RuntimeException("IOException in exportReport", e1); } catch (ReportingException e) { throw new RuntimeException("ReportingException in exportReport", e); } }
From source file:gov.noaa.pmel.tmap.las.product.server.ProductServerRunner.java
License:Open Source License
/** * // w w w. j av a 2 s . c om */ private void writeRSSFeed(String message) { lasRSSFeed.setChannelLink(serverURL); String url = ""; try { lasRSSFeed.setChannelTitle(lasConfig.getTitle()); url = url + serverURL + "/ProductServer.do?xml=" + productRequest.getLasRequest().toEncodedURLString(); } catch (JDOMException e) { log.warn("Error setting title on RSS feed."); } catch (UnsupportedEncodingException e) { log.warn("Error encoding the product URL for the RSS feed."); } if (JSESSIONID != null && !JSESSIONID.equals("")) { url = url + "&JSESSIONID=" + JSESSIONID; } DateTime now = new DateTime(new Date()).withZone(DateTimeZone.UTC); DateTimeFormatter format = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss z"); String pubDateText = format.print(now); lasRSSFeed.addItem(message + " " + productRequest.getOperationNames(), url, pubDateText); LASBackendRequest currentRequest = getCurrentBackendRequest(); currentRequest.mapResultToURL(serverURL, "rss"); String feedFileName = currentRequest.getResultAsFile("rss"); File feedFile = new File(feedFileName); lasRSSFeed.write(feedFile); }
From source file:helper.JodaTimeHelper.java
public String calculateDateTime() { DateTime dt = new DateTime(); dt = dt.withZone(DateTimeZone.forID("-05:00")); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); return fmt.print(dt); }
From source file:hudson.plugins.collabnet.orchestrate.DefaultBuildToJSON.java
License:Apache License
/** * Converts the standard timestamp from Java format to EventQ's format. * * * @param time the time to convert/*from w w w.j av a 2 s . com*/ * @return the formatted time */ public String convertTime(Date time) { DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC); return dateTimeFormatter.print(time.getTime()); }
From source file:imas.planning.entity.FlightEntity.java
private String convertTimezone(Date date, String countryName) { DateTime original = new DateTime(date.getTime()); DateTimeZone dtz = DateTimeZone.getDefault(); original.withZone(dtz);/* w w w .ja v a2 s . co m*/ Set<String> tzIds = DateTimeZone.getAvailableIDs(); for (String timeZoneId : tzIds) { if (timeZoneId.contains(countryName)) { dtz = DateTimeZone.forID(timeZoneId); break; } } DateTime dt = original.toDateTime(dtz); DateTimeFormatter dtfOut = DateTimeFormat.forPattern("MMM dd yyyy HH:mm:ss zzz"); return dtfOut.print(dt); }
From source file:Implement.DAO.BookingDAOImpl.java
@Override public void insertOfflineEngineBooking(String bookingDate, String tripDate, String tripTime, int noPackage, int packageID, String resourceNote, String customerName, String customerPhone, String customerEmail, String durationType, int duration, int smallestInterval, int providerID) { // construct dynamic sql for used resources DateTimeFormatter formatterDateAndHour = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss"); String travelTimeStr = tripDate; if (!durationType.equals("days")) { travelTimeStr += " " + tripTime + ":00"; } else {/*from w w w . j a v a 2s . c o m*/ travelTimeStr += " 00:00:00"; } DateTime travelTime = formatterDateAndHour.parseDateTime(travelTimeStr); DateTime endTime = new DateTime(travelTime); if (!durationType.equals("days")) { // change hours to minutes if (durationType.equals("hours")) { duration *= 60; } travelTime = travelTime.minusMinutes(duration); endTime = endTime.plusMinutes(duration); } else { travelTime = travelTime.minusDays(duration - 1); endTime = endTime.plusDays(duration + 1); } // loop each 5 minutes DateTimeFormatter fmtDate = DateTimeFormat.forPattern("MM/dd/YYYY"); DateTimeFormatter fmtTime = DateTimeFormat.forPattern("HH:mm"); String valueStr = "VALUES "; DateTime eachTime = new DateTime(travelTime); String date = fmtDate.print(eachTime); String time = fmtTime.print(eachTime); valueStr += " (@ResourceIDVar,'" + date + "','" + time + "',@NoUsedResourcesVar, @providerIDVar)"; eachTime = eachTime.plusMinutes(smallestInterval); while (eachTime.isBefore(endTime)) { date = fmtDate.print(eachTime); time = fmtTime.print(eachTime); valueStr += ",(@ResourceIDVar,'" + date + "','" + time + "',@NoUsedResourcesVar, @providerIDVar)"; eachTime = eachTime.plusMinutes(smallestInterval); } String insertStmt = "INSERT INTO UsedResources(ResourceID, TripDate, TripTime, NoUsedResources, ProviderID) "; insertStmt += valueStr; // Build Param Condition For Procedure String paramCondition = "@ResourceIDVar INT, @NoUsedResourcesVar INT, @providerIDVar INT"; simpleJdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("InsertOfflineBooking"); SqlParameterSource in = new MapSqlParameterSource().addValue("bookingDate", bookingDate) .addValue("providerID", providerID).addValue("tripDate", tripDate).addValue("tripTime", tripTime) .addValue("noPackage", noPackage).addValue("packageID", packageID) .addValue("resourceNote", resourceNote).addValue("customerName", customerName) .addValue("customerPhone", customerPhone).addValue("customerEmail", customerEmail) .addValue("InsertStatement", insertStmt).addValue("ParmDefinition", paramCondition); simpleJdbcCall.execute(in); }
From source file:Implement.DAO.BookingDAOImpl.java
@Override public void insertOfflineBooking(int providerID, int days, int hours, int minutes, long bookingTime, long tripTime, String dateStr, String timeStr, String customerName, String customerPhone, String email, List<OfflineResourceDTO> offlineResources, int smallestInterval, long resourceTime) { DateTimeFormatter fmtDate = DateTimeFormat.forPattern("MM/dd/YYYY"); DateTimeFormatter fmtTime = DateTimeFormat.forPattern("HH:mm"); // construct dynamic sql for used resources DateTimeFormatter formatterDateAndHour = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss"); String travelTimeStr = dateStr; if (days == 0) { travelTimeStr += " " + timeStr + ":00"; } else {//from w w w . j a v a 2 s . com travelTimeStr += " 00:00:00"; } // insert offline resources first int i = 0; OfflineResourceDTO offlineResource = offlineResources.get(i); int providerResurceID = offlineResource.getProviderResourceID(); int resourceHours = offlineResource.getHours(); int resourceMinutes = offlineResource.getMinutes(); int resourceDays = offlineResource.getDays(); int noUnits = offlineResource.getNoUnits(); String offlineResourceValue = "VALUES "; offlineResourceValue += "(@offlineBookingIDVar, " + providerResurceID + "," + noUnits + "," + resourceHours + "," + resourceMinutes + "," + resourceDays + ")"; String usedResourceValue = "VALUES "; DateTime travelTime = formatterDateAndHour.parseDateTime(travelTimeStr); DateTime endTime = new DateTime(travelTime); if (resourceDays > 0) { endTime = endTime.plusDays(resourceDays); } else { // change hours to minutes int duration = resourceHours * 60 + resourceMinutes; endTime = endTime.plusMinutes(duration); } // loop each 5 minutes DateTime eachTime = new DateTime(travelTime); String date = fmtDate.print(eachTime); String time = fmtTime.print(eachTime); int usedResouceMinutes = eachTime.getMinuteOfDay(); DateTime usedResourceOnlyDate = formatterDateAndHour.parseDateTime(date + " 00:00:00"); long usedResourceMil = usedResourceOnlyDate.getMillis(); usedResourceValue += " (" + providerResurceID + "," + usedResourceMil + "," + usedResouceMinutes + "," + noUnits + ",'" + date + "','" + time + "',@bookingCodeVar,@offlineBookingIDVar)"; eachTime = eachTime.plusMinutes(smallestInterval); while (eachTime.isBefore(endTime)) { date = fmtDate.print(eachTime); time = fmtTime.print(eachTime); usedResourceOnlyDate = formatterDateAndHour.parseDateTime(date + " 00:00:00"); usedResourceMil = usedResourceOnlyDate.getMillis(); usedResouceMinutes = eachTime.getMinuteOfDay(); usedResourceValue += ",(" + providerResurceID + "," + usedResourceMil + "," + usedResouceMinutes + "," + noUnits + ",'" + date + "','" + time + "',@bookingCodeVar,@offlineBookingIDVar)"; eachTime = eachTime.plusMinutes(smallestInterval); } i++; int resourceLength = offlineResources.size(); for (; i < resourceLength; i++) { offlineResource = offlineResources.get(i); providerResurceID = offlineResource.getProviderResourceID(); resourceHours = offlineResource.getHours(); resourceMinutes = offlineResource.getMinutes(); resourceDays = offlineResource.getDays(); noUnits = offlineResource.getNoUnits(); offlineResourceValue += ",(@offlineBookingIDVar, " + providerResurceID + "," + noUnits + "," + resourceHours + "," + resourceMinutes + "," + resourceDays + ")"; travelTime = formatterDateAndHour.parseDateTime(travelTimeStr); endTime = new DateTime(travelTime); if (resourceDays > 0) { endTime = endTime.plusDays(resourceDays); } else { // change hours to minutes int duration = resourceHours * 60 + resourceMinutes; endTime = endTime.plusMinutes(duration); } // loop each 5 minutes eachTime = new DateTime(travelTime); date = fmtDate.print(eachTime); time = fmtTime.print(eachTime); usedResouceMinutes = eachTime.getMinuteOfDay(); usedResourceOnlyDate = formatterDateAndHour.parseDateTime(date + " 00:00:00"); usedResourceMil = usedResourceOnlyDate.getMillis(); usedResourceValue += ",(" + providerResurceID + "," + usedResourceMil + "," + usedResouceMinutes + "," + noUnits + ",'" + date + "','" + time + "',@bookingCodeVar,@offlineBookingIDVar)"; eachTime = eachTime.plusMinutes(smallestInterval); while (eachTime.isBefore(endTime)) { date = fmtDate.print(eachTime); time = fmtTime.print(eachTime); usedResourceOnlyDate = formatterDateAndHour.parseDateTime(date + " 00:00:00"); usedResourceMil = usedResourceOnlyDate.getMillis(); usedResouceMinutes = eachTime.getMinuteOfDay(); usedResourceValue += ",(" + providerResurceID + "," + usedResourceMil + "," + usedResouceMinutes + "," + noUnits + ",'" + date + "','" + time + "',@bookingCodeVar,@offlineBookingIDVar)"; eachTime = eachTime.plusMinutes(smallestInterval); } } String resourceInsertingStmt = "INSERT INTO OfflineResource(OfflineBookingID, ProviderResourceID, NoUnits," + "Hours, Minutes,Days) "; resourceInsertingStmt += offlineResourceValue; String resourceInsertingParmDefinition = "@offlineBookingIDVar INT"; String usedResourceInsertingStmt = "INSERT INTO UsedProviderResource(ProviderResourceID, Date, Time, NoUsedResources," + "DateStr,TimeStr,BookingCode,OfflineBookingID)"; usedResourceInsertingStmt += usedResourceValue; String usedResourceInsertingParmDefinition = "@bookingCodeVar NVARCHAR(10)," + "@offlineBookingIDVar INT"; simpleJdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("InsertNewOfflineBooking"); SqlParameterSource in = new MapSqlParameterSource().addValue("days", days).addValue("minutes", minutes) .addValue("hours", hours).addValue("bookingTime", bookingTime).addValue("tripTime", tripTime) .addValue("dateStr", dateStr).addValue("timeStr", timeStr).addValue("customerName", customerName) .addValue("customerPhone", customerPhone).addValue("customerPhone", customerPhone) .addValue("email", email).addValue("providerID", providerID) .addValue("ResourceInsertingStmt", resourceInsertingStmt) .addValue("ResourceInsertingParmDefinition", resourceInsertingParmDefinition) .addValue("UsedResourceInsertingStmt", usedResourceInsertingStmt) .addValue("UsedResourceInsertingParmDefinition", usedResourceInsertingParmDefinition); simpleJdbcCall.execute(in); }