List of usage examples for org.joda.time MutableDateTime toString
public String toString(String pattern)
From source file:DDTDate.java
License:Apache License
/** * This function will populate the varsMap with new copies of values related to display format of date & time stamps. * Those values are based on the class (static) date variable that is currently in use. * Those values can later be used in verification of UI elements that are date-originated but may change in time (say, today's date, month, year - etc.) * The base date that is used is Locale dependent (currently, the local is assumed to be that of the workstation running the software.) * When relevant, values are provided in various styles (SHORT, MEDIUM, LONG, FULL) - not all date elements have all those versions available. * The purpose of this 'exercise' is to set up the facility for the user to verify any component of date / time stamps independently of one another or 'traditional' formatting. * * The variables maintained here are formatted with a prefix to distinguish them from other, user defined variables. * * @TODO: enable Locale modifications (at present the test machine's locale is considered and within a test session only one locale can be tested) * WikiPedia: https://en.wikipedia.org/wiki/Date_format_by_country * Stack Overflow (coes) http://stackoverflow.com/questions/3191664/list-of-all-locales-and-their-short-codes * @param varsMap/* w ww .j a v a 2 s . co m*/ */ private void maintainDateProperties(Hashtable<String, Object> varsMap) throws Exception { String prefix = "$"; try { // Build formatting objects for each of the output styles DateFormat shortStyleFormatter = DateFormat.getDateInstance(DateFormat.SHORT, getLocale()); DateFormat mediumStyleFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale()); DateFormat longStyleFormatter = DateFormat.getDateInstance(DateFormat.LONG, getLocale()); DateFormat fullStyleFormatter = DateFormat.getDateInstance(DateFormat.FULL, getLocale()); // Use a dedicated variable to hold values of formatting results to facilitate debugging // @TODO (maybe) when done debugging - convert to inline calls to maintainDateProperty ... String formatValue; // Examples reflect time around midnight of February 6 2014 - actual values DO NOT include quotes (added here for readability) MutableDateTime theReferenceDate = getReferenceDate(); //getReferenceDateAdjustedForTimeZone(); // Default Date using DDTSettings pattern. formatValue = new SimpleDateFormat(defaultDateFormat()).format(theReferenceDate.toDate()); maintainDateProperty(prefix + "defaultDate", formatValue, varsMap); // Short Date - '2/6/14' formatValue = shortStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "shortDate", formatValue, varsMap); // Medium Date - 'Feb 6, 2014' formatValue = mediumStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "mediumDate", formatValue, varsMap); // Long Date - 'February 6, 2014' formatValue = longStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "longDate", formatValue, varsMap); // Full Date 'Thursday, February 6, 2014' formatValue = fullStyleFormatter.format(theReferenceDate.toDate()); maintainDateProperty(prefix + "fullDate", formatValue, varsMap); // hours : minutes : seconds : milliseconds (broken to separate components) - formatValue = theReferenceDate.toString("hh:mm:ss:SSS"); if (formatValue.toString().contains(":")) { String[] hms = split(formatValue.toString(), ":"); if (hms.length > 3) { // Hours - '12' formatValue = hms[0]; maintainDateProperty(prefix + "hours", formatValue, varsMap); // Minutes - '02' formatValue = hms[1]; maintainDateProperty(prefix + "minutes", formatValue, varsMap); // Seconds - '08' formatValue = hms[2]; maintainDateProperty(prefix + "seconds", formatValue, varsMap); // Milliseconds - '324' formatValue = hms[3]; maintainDateProperty(prefix + "milliseconds", formatValue, varsMap); // Hours in 24 hours format - '23' formatValue = theReferenceDate.toString("HH"); maintainDateProperty(prefix + "hours24", formatValue, varsMap); } else setException("Failed to format reference date to four time units!"); } else { setException("Failed to format reference date to its time units!"); } // hours : minutes : seconds (default timestamp) - '12:34:56' formatValue = theReferenceDate.toString("hh:mm:ss"); maintainDateProperty(prefix + "timeStamp", formatValue, varsMap); // Short Year - '14' formatValue = theReferenceDate.toString("yy"); maintainDateProperty(prefix + "shortYear", formatValue, varsMap); // Long Year - '2014' formatValue = theReferenceDate.toString("yyyy"); maintainDateProperty(prefix + "longYear", formatValue, varsMap); // Short Month - '2' formatValue = theReferenceDate.toString("M"); maintainDateProperty(prefix + "shortMonth", formatValue, varsMap); // Padded Month - '02' formatValue = theReferenceDate.toString("MM"); maintainDateProperty(prefix + "paddedMonth", formatValue, varsMap); // Short Month Name - 'Feb' formatValue = theReferenceDate.toString("MMM"); maintainDateProperty(prefix + "shortMonthName", formatValue, varsMap); // Long Month Name - 'February' formatValue = theReferenceDate.toString("MMMM"); maintainDateProperty(prefix + "longMonthName", formatValue, varsMap); // Week in Year - '2014' (the year in which this week falls) formatValue = String.valueOf(theReferenceDate.getWeekyear()); maintainDateProperty(prefix + "weekYear", formatValue, varsMap); // Short Day in date stamp - '6' formatValue = theReferenceDate.toString("d"); maintainDateProperty(prefix + "shortDay", formatValue, varsMap); // Padded Day in date stamp - possibly with leading 0 - '06' formatValue = theReferenceDate.toString("dd"); maintainDateProperty(prefix + "paddedDay", formatValue, varsMap); // Day of Year - '37' formatValue = theReferenceDate.toString("D"); maintainDateProperty(prefix + "yearDay", formatValue, varsMap); // Short Day Name - 'Thu' formatValue = theReferenceDate.toString("E"); maintainDateProperty(prefix + "shortDayName", formatValue, varsMap); // Long Day Name - 'Thursday' DateTime dt = new DateTime(theReferenceDate.toDate()); DateTime.Property dowDTP = dt.dayOfWeek(); formatValue = dowDTP.getAsText(); maintainDateProperty(prefix + "longDayName", formatValue, varsMap); // AM/PM - 'AM' formatValue = theReferenceDate.toString("a"); maintainDateProperty(prefix + "ampm", formatValue, varsMap); // Era - (BC/AD) formatValue = theReferenceDate.toString("G"); maintainDateProperty(prefix + "era", formatValue, varsMap); // Time Zone - 'EST' formatValue = theReferenceDate.toString("zzz"); maintainDateProperty(prefix + "zone", formatValue, varsMap); addComment( "Date variables replenished for date: " + fullStyleFormatter.format(theReferenceDate.toDate())); addComment(theReferenceDate.toString()); System.out.println(getComments()); } catch (Exception e) { setException(e); } }
From source file:DDTDate.java
License:Apache License
/** * Creates the output the user indicated in the input (outputType component) subject to the requested style (outputStyle) component * @return//from w w w . j a v a2 s. c o m */ private String createOutput() { String result = ""; try { // If needed, adjust the reference date by the number and type of units specified - as per the time zone if (getUnits() != 0) { //setReferenceDate(getReferenceDateAdjustedForTimeZone()); getReferenceDate().add(getDurationType(), getUnits()); } // Create date formatters to be used for all varieties - the corresponding date variables are always set for convenience purposes DateFormat shortFormatter = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat mediumFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM); DateFormat longFormatter = DateFormat.getDateInstance(DateFormat.LONG); DateFormat fullFormatter = DateFormat.getDateInstance(DateFormat.FULL); // Build the specific formatter specified DateFormat formatter = null; switch (getOutputStyle().toLowerCase()) { case "medium": { formatter = mediumFormatter; break; } case "long": { formatter = longFormatter; break; } case "full": { formatter = fullFormatter; break; } default: formatter = shortFormatter; } // output style switch // construct the specified result - one at a time MutableDateTime theReferenceDate = getReferenceDate(); //getReferenceDateAdjustedForTimeZone(); switch (getOutputType().toLowerCase()) { case "date": { result = formatter.format(theReferenceDate.toDate()); break; } case "time": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("hh:mm:ss"); break; } default: result = theReferenceDate.toString("hh:mm:ss.SSS"); } break; } // separate time components case "hour": case "minute": case "second": case "hour24": { String tmp = theReferenceDate.toString("hh:mm:ss"); if (tmp.toString().contains(":")) { String[] hms = split(tmp.toString(), ":"); if (hms.length > 2) { switch (getOutputType().toLowerCase()) { case "hour": { // Hour - '12' result = hms[0]; break; } case "minute": { // Minutes - '34' result = hms[1]; break; } case "second": { // Second - '56' result = hms[2]; break; } case "hour24": { // Hour - '23' result = theReferenceDate.toString("HH"); break; } default: result = hms[0]; } // switch for individual time component } // three parts of time components } // timestamp contains separator ":" break; } // Hours, Minutes, Seconds case "year": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("yy"); break; } default: result = theReferenceDate.toString("yyyy"); } break; } case "month": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("M"); break; } case "medium": { // padded with 0 result = theReferenceDate.toString("MM"); break; } case "long": { // short name 'Feb' result = theReferenceDate.toString("MMM"); break; } default: // Full name 'September' result = theReferenceDate.toString("MMMM"); } break; } case "day": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("d"); break; } case "medium": { result = theReferenceDate.toString("dd"); break; } default: result = theReferenceDate.toString("dd"); } } case "doy": { result = theReferenceDate.toString("D"); break; } case "dow": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("E"); break; } case "medium": { DateTime dt = new DateTime(theReferenceDate.toDate()); DateTime.Property dowDTP = dt.dayOfWeek(); result = dowDTP.getAsText(); break; } default: result = theReferenceDate.toString("E"); } break; } // day of week case "zone": { result = theReferenceDate.toString("zzz"); break; } case "era": { result = theReferenceDate.toString("G"); break; } case "ampm": { result = theReferenceDate.toString("a"); break; } default: { setException("Invalid Output Unit - cannot set output"); } // Create full date variables for the short, medium, long, full styles } // output type switch } // try constructing result catch (Exception e) { setException(e); } finally { return result; } }
From source file:com.simopuve.rest.SimopuveRESTServices.java
@Path("/reports") @GET//from w ww . ja v a 2 s . c om @Produces("text/plain") public String getReportByDateInterval(@QueryParam("from") String from, @QueryParam("to") String to) { Date start; Date end; if (from == null) { start = new Date(); } else { try { start = new SimpleDateFormat("dd/MM/yyyy").parse(from); } catch (ParseException ex) { start = new Date(); Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.SEVERE, null, ex); } } if (to == null) { end = new Date(); } else { try { end = new SimpleDateFormat("dd/MM/yyyy").parse(to); } catch (ParseException ex) { end = new Date(); Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.SEVERE, null, ex); } } org.joda.time.format.DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyy"); DateTime startDate = new DateTime(start); DateTime endDate = new DateTime(end); Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.INFO, "Received UA: " + start); Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.INFO, "Received UA: " + from); Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.INFO, "Received UA: " + startDate); MutableDateTime currentDate = new MutableDateTime(startDate); List<PDVSurvey> surveyList = new ArrayList<>(); File currentFolder; File mallFolder; File officeFolder; File tmpFolder; String varPath; String tmpPath; PDVSurvey survey = null; Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.INFO, "Received startdate: " + startDate); while (!currentDate.isAfter(endDate)) { varPath = new StringBuilder(System.getProperty("jboss.server.data.dir")).append("/PDV/") .append(currentDate.toString(fmt)).append("/").toString(); currentFolder = new File(varPath); if (currentFolder.exists()) { mallFolder = new File(varPath + "/Mall"); officeFolder = new File(varPath + "/Oficina"); if (mallFolder.exists()) { for (File fileEntry : mallFolder.listFiles()) { try { Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.INFO, "archivo {0} ", fileEntry.getName()); tmpPath = varPath + "/Mall/" + fileEntry.getName(); survey = getPDVSurveyFromFile(tmpPath, true); surveyList.add(survey); } catch (IOException ex) { Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.SEVERE, null, ex); } } } if (officeFolder.exists()) { for (File fileEntry : officeFolder.listFiles()) { try { Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.INFO, "archivo {0} ", fileEntry.getName()); tmpPath = varPath + "/Oficina/" + fileEntry.getName(); survey = getPDVSurveyFromFile(tmpPath, false); surveyList.add(survey); } catch (IOException ex) { Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.SEVERE, null, ex); } } } } Logger.getLogger(SimopuveRESTServices.class.getName()).log(Level.INFO, "-+-+-+-tamao de lista {0} ", surveyList.size()); currentDate.addDays(1); } String filePath = new StringBuilder(System.getProperty("jboss.server.data.dir")) .append("/PDV/testFlow.xlsx").toString(); Workbook flowWorkbook = POIHelper.getWorkbookFromLocalReource("plantilla-base-flujo.xlsx"); FillFlowBaseSheet(surveyList, flowWorkbook.getSheetAt(0)); FillDetailBaseSheet(surveyList, flowWorkbook.getSheetAt(1)); POIHelper.writeWorkbookInPath(flowWorkbook, filePath); return "Listo"; }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Generates the day displays in the week panel *//*from w ww. j av a 2 s . com*/ private void generateDay() { // clear out the specifics smithsonian.removeAll(); headerBox.removeAll(); // add the day grid back in hourLabels = new DayGridLabel(); smithsonian.add(hourLabels, "cell 0 0,grow"); MutableDateTime increment = new MutableDateTime(weekStartTime); increment.setMillisOfDay(0); DateTime now = DateTime.now().withMillisOfDay(0); displayableList = getVisibleDisplayables(); for (int i = 0; i < 7; i++) { // add day views to the day grid this.daysOfWeekArray[i] = new DayPanel(true, this); this.daysOfWeekArray[i].setEvents( getDisplayablesInInterval(increment.toDateTime(), increment.toDateTime().plusDays(1)), increment.toDateTime()); this.daysOfWeekArray[i] .setBorder(BorderFactory.createMatteBorder(1, 0, 1, i == 6 ? 0 : 1, Colors.BORDER)); this.smithsonian.add(this.daysOfWeekArray[i], "cell " + (i + 1) + " 0,grow"); // add day titles to the title grid dayHeaders[i].setText(increment.toDateTime().toString(dayTitleFmt)); dayHeaders[i] .setFont(dayHeaders[i].getFont().deriveFont(increment.isEqual(now) ? Font.BOLD : Font.PLAIN)); increment.addDays(1); } // populate and set up the multiDayEventGrid populateMultidayEventGrid(); // setup week title increment.addDays(-1); // smart titles if (weekStartTime.getYear() != increment.getYear()) weekTitle .setText(weekStartTime.toString(monthDayYearFmt) + " - " + increment.toString(monthDayYearFmt)); else if (weekStartTime.getMonthOfYear() != increment.getMonthOfYear()) weekTitle.setText(weekStartTime.toString(monthDayFmt) + " - " + increment.toString(monthDayYearFmt)); else weekTitle.setText(weekStartTime.toString(monthDayFmt) + " - " + increment.toString(dayYearFmt)); // notify mini-calendar to change mainPanel.miniMove(time); }
From source file:de.pro.dbw.util.impl.DateConverter.java
License:Open Source License
public String convertLongToDateTime(Long millis, String pattern) { final MutableDateTime mdt = new MutableDateTime(millis); return mdt.toString(pattern); }
From source file:se.streamsource.streamflow.web.context.crystal.CrystalContext.java
License:Apache License
public TableValue motionchart() { final TableBuilder tableBuilder = new TableBuilder(module.valueBuilderFactory()); tableBuilder.column("CaseType", "Case type", "string").column("Week", "Week", "string") .column("Variation", "Variation", "number").column("Duration", "Duration", "number") .column("CaseCount", "Case count", "number").column("CasetypeOwner", "Casetype owner", "string"); final Logger logger = LoggerFactory.getLogger(getClass()); try {//from w ww .j a va2s . co m final String weekFormat = "yyyy'W'ww"; DateTime[] range = findRange(); logger.info( "Full range from " + range[0].toString(weekFormat) + " to " + range[1].toString(weekFormat)); // Find cases for each week Databases databases = new Databases(source.get()); final MutableDateTime from = new MutableDateTime(range[0]).dayOfWeek().set(1); while (from.isBefore(range[1])) { final MutableDateTime minWeek = from.copy(); databases.query(sql.getString("motionchart"), new Databases.StatementVisitor() { public void visit(PreparedStatement preparedStatement) throws SQLException { String fromWeek = from.toString(weekFormat); preparedStatement.setTimestamp(1, new Timestamp(from.toDate().getTime())); from.addWeeks(1); preparedStatement.setTimestamp(2, new Timestamp(from.toDate().getTime())); String toWeek = from.toString(weekFormat); logger.info("From " + fromWeek + " to " + toWeek); } }, new Databases.ResultSetVisitor() { public boolean visit(ResultSet visited) throws SQLException { tableBuilder.row().cell(visited.getString("casetype"), null) .cell(minWeek.toString(weekFormat), "v" + minWeek.weekOfWeekyear().get()) .cell(visited.getString("variationpct"), null) .cell((visited.getLong("average") / (1000 * 60 * 60)) + "", null) .cell(visited.getString("count"), null) .cell(visited.getString("casetype_owner"), null); return true; } }); } } catch (SQLException e) { logger.warn("Could not get statistics", e); } return tableBuilder.newTable(); }
From source file:se.toxbee.sleepfighter.service.AlarmPlannerService.java
License:Open Source License
/** * Reschedule an {@link Alarm}, that has gone of, to some minutes from now, * defined by the alarm itself.// w w w .java2 s. c o m * * @param alarmId * the alarm's id */ private void snooze(int alarmId) { Alarm alarm = SFApplication.get().getPersister().fetchAlarmById(alarmId); if (alarm == null) { throw new IllegalArgumentException("No alarm was found with given id"); } // Determine which time to schedule at by adding offset minutes from alarm to current time MutableDateTime dateTime = MutableDateTime.now(); int mins = alarm.getSnoozeConfig().getSnoozeTime(); dateTime.addMinutes(mins); long scheduleTime = dateTime.getMillis(); schedule(scheduleTime, alarm); showSnoozingNotification(alarm, dateTime.toString("HH:mm")); }