public void setMetaData(SectionDataIfc section) { if (section.getSectionMetaDataByLabel(SectionDataIfc.AUTHOR_TYPE) != null) { Integer authortype = new Integer(section.getSectionMetaDataByLabel(SectionDataIfc.AUTHOR_TYPE)); setSectionAuthorType(authortype); if (section .getSectionMetaDataByLabel(SectionDataIfc.AUTHOR_TYPE) .equals(SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL.toString())) { if (section.getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN) != null) { Integer numberdrawn = new Integer(section.getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN)); setNumberToBeDrawn(numberdrawn); } if (section.getSectionMetaDataByLabel(SectionDataIfc.POOLID_FOR_RANDOM_DRAW) != null) { Long poolid = new Long(section.getSectionMetaDataByLabel(SectionDataIfc.POOLID_FOR_RANDOM_DRAW)); setPoolIdToBeDrawn(poolid); } if (section.getSectionMetaDataByLabel(SectionDataIfc.POOLNAME_FOR_RANDOM_DRAW) != null) { String poolname = section.getSectionMetaDataByLabel(SectionDataIfc.POOLNAME_FOR_RANDOM_DRAW); setPoolNameToBeDrawn(poolname); String randomDrawDate = section.getSectionMetaDataByLabel(SectionDataIfc.QUESTIONS_RANDOM_DRAW_DATE); if (randomDrawDate != null && !"".equals(randomDrawDate)) { try { // The Date Time is in ISO format DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime drawDate = fmt.parseDateTime(randomDrawDate); // We need the locale to localize the output string Locale loc = new ResourceLoader().getLocale(); String drawDateString = DateTimeFormat.fullDate().withLocale(loc).print(drawDate); String drawTimeString = DateTimeFormat.fullTime().withLocale(loc).print(drawDate); setRandomQuestionsDrawDate(drawDateString); setRandomQuestionsDrawTime(drawTimeString); } catch (Exception e) { log.error("Unable to parse date text: " + randomDrawDate, e); } } } } } else { setSectionAuthorType(SectionDataIfc.QUESTIONS_AUTHORED_ONE_BY_ONE); } if (section.getSectionMetaDataByLabel(SectionDataIfc.QUESTIONS_ORDERING) != null) { Integer questionorder = new Integer(section.getSectionMetaDataByLabel(SectionDataIfc.QUESTIONS_ORDERING)); setQuestionOrdering(questionorder); } else { setQuestionOrdering(SectionDataIfc.AS_LISTED_ON_ASSESSMENT_PAGE); } }
@Test public void testIsoDateFormatDateOptionalTimeUTC() { DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC); long millis = formatter.parseMillis("1970-01-01T00:00:00Z"); assertThat(millis, equalTo(0l)); millis = formatter.parseMillis("1970-01-01T00:00:00.001Z"); assertThat(millis, equalTo(1l)); millis = formatter.parseMillis("1970-01-01T00:00:00.1Z"); assertThat(millis, equalTo(100l)); millis = formatter.parseMillis("1970-01-01T00:00:00.1"); assertThat(millis, equalTo(100l)); millis = formatter.parseMillis("1970-01-01T00:00:00"); assertThat(millis, equalTo(0l)); millis = formatter.parseMillis("1970-01-01"); assertThat(millis, equalTo(0l)); millis = formatter.parseMillis("1970"); assertThat(millis, equalTo(0l)); try { formatter.parseMillis("1970 kuku"); assert false : "formatting should fail"; } catch (IllegalArgumentException e) { // all is well } // test offset in format millis = formatter.parseMillis("1970-01-01T00:00:00-02:00"); assertThat(millis, equalTo(TimeValue.timeValueHours(2).millis())); }
@Test public void testIsoDateFormatDateTimeNoMillisUTC() { DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC); long millis = formatter.parseMillis("1970-01-01T00:00:00Z"); assertThat(millis, equalTo(0l)); }
/** @return */ private DateTime getDate() { String s = field.get(0).get(0).toString(); DateTimeParser[] parsers = {DateTimeFormat.forPattern("yyyMMMddHH").getParser()}; DateTimeFormatter inputFormatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); return inputFormatter.withLocale(Locale.US).parseDateTime(s); }
/** * Constructs a new ReportGenerator. * * @param applicationName the application name being analyzed * @param dependencies the list of dependencies * @param analyzers the list of analyzers used * @param properties the database properties (containing timestamps of the NVD CVE data) */ public ReportGenerator( String applicationName, List<Dependency> dependencies, List<Analyzer> analyzers, DatabaseProperties properties) { velocityEngine = createVelocityEngine(); context = createContext(); velocityEngine.init(); final EscapeTool enc = new EscapeTool(); final DateTime dt = DateTime.now(); final DateTimeFormatter dateFormat = DateTimeFormat.forPattern("MMM d, yyyy 'at' HH:mm:ss z"); final DateTimeFormatter dateFormatXML = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); // final Date d = new Date(); // final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy 'at' HH:mm:ss z"); // final DateFormat dateFormatXML = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); final String scanDate = dateFormat.print(dt); final String scanDateXML = dateFormatXML.print(dt); context.put("applicationName", applicationName); context.put("dependencies", dependencies); context.put("analyzers", analyzers); context.put("properties", properties); context.put("scanDate", scanDate); context.put("scanDateXML", scanDateXML); context.put("enc", enc); context.put("version", Settings.getString(Settings.KEYS.APPLICATION_VERSION, "Unknown")); }
public static void main(String[] args) { String dayStrBegin = "2016-03-14"; String dayStrEnd = "2016-03-20"; String datePattern = "yyyy-MM-dd"; DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(datePattern); LocalDate localDateStart = dateFormatter.parseLocalDate(dayStrBegin); LocalDate localDateEnd = dateFormatter.parseLocalDate(dayStrEnd); // 比较大小,不返回相差的天数 // localDateStart.compareTo(localDateEnd); // 减去一个Period,不能应用于localDateEnd // localDateStart.minus(ReadablePeriod); // minus的入参是ReadablePeriod // Duration ninetyDays = new Duration(NINETY_DAYS_MILLI); /* * Period ninetyDays = new Period(NINETY_DAYS_MILLI); LocalDate limitStart = localDateEnd.minus(ninetyDays); if * (localDateStart.compareTo(limitStart) != -1) { System.out.println("Hi, there"); } */ Days durationDays = Days.daysBetween(localDateStart, localDateEnd); if (durationDays.getDays() <= 90) { System.out.println("Hi, there"); } }
/** * Format date to hh:mm:ss * * @param date * @return */ public static String formatTime(Date date) { if (date != null) { DateTimeFormatter fmt = DateTimeFormat.forPattern(TIME_SHORT_PATTERN); return fmt.print(new DateTime(date)); } return null; }
private RunTimeElements getNextSingleStarts(DateTime baseDate) { DateTimeFormatter fmtDate = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTimeFormatter fmtDateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); RunTimeElements result = new RunTimeElements(baseDate); logger.debug(getDay().size() + " day elements detected."); Iterator<String> it = getDay().iterator(); while (it.hasNext()) { String dayString = it.next(); logger.debug("parsing day string " + dayString); List<Integer> days = JodaTools.getJodaWeekdays(dayString); for (int i = 0; i < days.size(); i++) { DateTime nextWeekDay = JodaTools.getNextWeekday(baseDate, days.get(i)); logger.debug("calculated date " + fmtDate.print(nextWeekDay)); List<Period> periods = getPeriod(); Iterator<Period> itP = periods.iterator(); logger.debug(periods.size() + " periods found."); while (itP.hasNext()) { Period p = itP.next(); JSObjPeriod period = new JSObjPeriod(objFactory); period.setObjectFieldsFrom(p); DateTime start = period.getDtSingleStartOrNull(nextWeekDay); if (start != null) { logger.debug("start from period " + fmtDateTime.print(start)); if (start.isBefore(baseDate)) { start = start.plusWeeks(1); logger.debug("start is corrected to " + fmtDateTime.print(start)); } result.add(new RunTimeElement(start, period.getWhenHoliday())); } } } // Collections.sort(result, DateTimeComparator.getInstance()); } return result; }
public List<ExternalWorklog> parseWorklog() throws IOException { final CSVReader reader = new CSVReader(new StringReader(csv), ',', '"', "#", true, true, true, true, false); final String[] header = reader.getAllFieldsInLine(); verifyHeader(header); final DateTimeFormatter dateFormat = DateTimeFormat.forPattern("yyyy-MM-dd"); final List<ExternalWorklog> result = Lists.newArrayList(); for (; ; ) { final ExternalWorklog worklogItem = new ExternalWorklog(); final String[] line; try { line = reader.getAllFieldsInLine(); } catch (EOFException e) { break; } worklogItem.setStartDate(dateFormat.parseDateTime(line[0]).toDate()); worklogItem.setAuthor( userNameMapper.getUsernameForLoginName(StringUtils.strip(line[2] + " " + line[1]))); worklogItem.setTimeSpent((long) (UNITS_PER_HOUR * Double.parseDouble(line[5]))); worklogItem.setComment(line[6]); result.add(worklogItem); } return result; }
@Override public Object adapt(Object value, Map<String, Object> context) { if (value == null || !(value instanceof String)) { return value; } String format = this.get("format", DEFAULT_FORMAT); DateTimeFormatter fmt = DateTimeFormat.forPattern(format); DateTime dt; try { dt = fmt.parseDateTime((String) value); } catch (Exception e) { throw new IllegalArgumentException("Invalid value: " + value, e); } String type = this.get("type", null); if ("LocalDate".equals(type)) { return dt.toLocalDate(); } if ("LocalTime".equals(type)) { return dt.toLocalTime(); } if ("LocalDateTime".equals(type)) { return dt.toLocalDateTime(); } return dt; }
private void ensureOpen() throws IOException { if (table == null) { table = DataIO.table(new File(file), null); rowsIterator = (TableIterator<String[]>) table.rows().iterator(); /* * If tStart is null then the reader try to read all the value in the file, nb time step constant. */ if (tStart == null) { String secondTime = null; // get the first time in the file. if (rowsIterator.hasNext()) { String[] row = rowsIterator.next(); tStart = row[1]; } // get the time of the second row in the file. if (rowsIterator.hasNext()) { String[] row = rowsIterator.next(); secondTime = row[1]; } // the dt is equal to the fifference of the time of 2 rows. tTimestep = formatter.parseDateTime(secondTime).getMinuteOfDay() - formatter.parseDateTime(tStart).getMinuteOfDay(); // close and reopen to read the row. rowsIterator.close(); rowsIterator = (TableIterator<String[]>) table.rows().iterator(); } } }
/** * @param isNullable isNullable * @param earliest lower boundary date * @param latest upper boundary date * @param onlyBusinessDays only business days * @return a list of boundary dates */ public List<String> positiveCase( boolean isNullable, String earliest, String latest, boolean onlyBusinessDays) { List<String> values = new LinkedList<>(); if (earliest.equalsIgnoreCase(latest)) { values.add(earliest); if (isNullable) { values.add(""); } return values; } DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime earlyDate = parser.parseDateTime(earliest); DateTime lateDate = parser.parseDateTime(latest); String earlyDay = parser.print(earlyDate); String nextDay = getNextDay(earlyDate.toString().substring(0, 10), onlyBusinessDays); String prevDay = getPreviousDay(lateDate.toString().substring(0, 10), onlyBusinessDays); String lateDay = parser.print(lateDate); values.add(earlyDay); values.add(nextDay); values.add(prevDay); values.add(lateDay); if (isNullable) { values.add(""); } return values; }
/** * Grab random holiday from the equivalence class that falls between the two dates * * @param earliest the earliest date parameter as defined in the model * @param latest the latest date parameter as defined in the model * @return a holiday that falls between the dates */ public String getRandomHoliday(String earliest, String latest) { String dateString = ""; DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime earlyDate = parser.parseDateTime(earliest); DateTime lateDate = parser.parseDateTime(latest); List<Holiday> holidays = new LinkedList<>(); int min = Integer.parseInt(earlyDate.toString().substring(0, 4)); int max = Integer.parseInt(lateDate.toString().substring(0, 4)); int range = max - min + 1; int randomYear = (int) (Math.random() * range) + min; for (Holiday s : EquivalenceClassTransformer.HOLIDAYS) { holidays.add(s); } Collections.shuffle(holidays); for (Holiday holiday : holidays) { dateString = convertToReadableDate(holiday.forYear(randomYear)); if (toDate(dateString).after(toDate(earliest)) && toDate(dateString).before(toDate(latest))) { break; } } return dateString; }
public static void testLocale() { System.out.println("演示Locale"); DateTime dateTime = new DateTime().withZone(DateTimeZone.UTC); // 打印中文与英文下不同长度的日期格式串 System.out.println("S: " + DateUtils.formatDateTime(dateTime, "SS", "zh")); System.out.println("M: " + DateUtils.formatDateTime(dateTime, "MM", "zh")); System.out.println("L: " + DateUtils.formatDateTime(dateTime, "LL", "zh")); System.out.println("XL: " + DateUtils.formatDateTime(dateTime, "FF", "zh")); System.out.println(""); System.out.println("S: " + DateUtils.formatDateTime(dateTime, "SS", "en")); System.out.println("M: " + DateUtils.formatDateTime(dateTime, "MM", "en")); System.out.println("L: " + DateUtils.formatDateTime(dateTime, "LL", "en")); System.out.println("XL: " + DateUtils.formatDateTime(dateTime, "FF", "en")); System.out.println(""); System.out.println(""); // 直接打印TimeStamp, 日期是M,时间是L DateTimeFormatter formatter = DateTimeFormat.forStyle("ML").withLocale(new Locale("zh")).withZone(DateTimeZone.UTC); System.out.println("ML Mix: " + formatter.print(dateTime.getMillis())); // 只打印日期不打印时间 System.out.println("Date only :" + DateUtils.formatDateTime(dateTime, "M-", "zh")); }
// @@author A0124206W // checks if explicit mentioned dates in the form of MM/dd/yyyy and // MM/dd/yyyy HH:mm are valid. private boolean isValidExplicitDate(String dateString) throws Exception { logger.log(Level.FINE, "checking date: " + dateString); dateString = dateString.replace(DATE_SPLITTER_SLASH, DATE_SPLITTER_DOT); if (!dateString.contains(DATE_SPLITTER_DOT)) { // is not an explicit date return true; } // check if date has time and if there is exactly one date if (dateString.contains(DATE_SPLITTER_COLON) && (dateString.length() <= NUM_CHAR_DATE_TIME_INPUT)) { timeFormatter.parseDateTime(dateString); } else if (dateString.length() <= NUM_CHAR_DATE_INPUT) { timeFormatter.parseDateTime(dateString + DUMMY_TIME); } else { // there is more than 1 date (should be 2) String[] dateStringArray = splitDates(dateString); if (dateStringArray.length != DATE_GROUP_TWO_DATE) { throw new Exception(); } else { isValidExplicitDate(dateStringArray[PARSED_DATE_TEXT_FIRST]); isValidExplicitDate(dateStringArray[PARSED_DATE_TEXT_SECOND]); } } return true; }
public static String formatUTCToLocal(String datetime) { String returnTimeDate = ""; DateTime dtUTC = null; DateTimeZone timezone = DateTimeZone.getDefault(); DateTimeFormatter formatDT = DateTimeFormat.forPattern("MMM dd, yyyy hh:mma"); try { DateTime dateDateTime1 = formatDT.parseDateTime(datetime); DateTime now = new DateTime(); DateTime nowUTC = new LocalDateTime(now).toDateTime(DateTimeZone.UTC); long instant = now.getMillis(); long instantUTC = nowUTC.getMillis(); long offset = instantUTC - instant; // convert to local time dtUTC = dateDateTime1.withZoneRetainFields(DateTimeZone.UTC); // dtUTC = dateDateTime1.toDateTime(timezone); dtUTC = dtUTC.plusMillis((int) offset); returnTimeDate = dtUTC.toString(formatDT); } catch (Exception e) { returnTimeDate = "null"; e.printStackTrace(); } return returnTimeDate; }
public static void testTimeZone() { System.out.println("演示时区"); String format = "yyyy-MM-dd HH:mm:ss zZZ"; // DateTime的毫秒即System的毫秒,即1970到现在的UTC的毫秒数. System.out.println(new DateTime().getMillis() + " " + System.currentTimeMillis()); // 将日期按默认时区打印 DateTime fooDate = new DateTime(1978, 6, 1, 12, 10, 8, 0); System.out.println( fooDate.toString(format) + " " + fooDate.getMillis()); // "1978-06-01 12:10:08" // 将日期按UTC时区打印 DateTime zoneWithUTC = fooDate.withZone(DateTimeZone.UTC); System.out.println( zoneWithUTC.toString(format) + " " + zoneWithUTC.getMillis()); // "1978-06-01 04:10:08", sameMills // 按不同的时区分析字符串,得到不同的时间 String dateString = "1978-06-01 12:10:08"; DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); DateTime parserResult1 = fmt.withZone(DateTimeZone.forID("US/Pacific")).parseDateTime(dateString); DateTime parserResult2 = fmt.withZone(DateTimeZone.UTC).parseDateTime(dateString); System.out.println(parserResult1.toString(format) + " " + parserResult1.getMillis()); System.out.println(parserResult2.toString(format) + " " + parserResult2.getMillis()); }
@PostConstruct public void createSampleData() { // create sample task groups TaskGroup inbox = persist(prepareTaskGroup(1L, "Inbox")); TaskGroup shoppingList = persist(prepareTaskGroup(2L, "Shopping list")); TaskGroup atHome = persist(prepareTaskGroup(3L, "At home")); TaskGroup atWork = persist(prepareTaskGroup(4L, "At work")); // create sample tasks persist(prepareTask(1L, "Buy some fruits", shoppingList, TaskPriority.NORMAL, null, null)); persist( prepareTask( 2L, "Write article for personal blog", atHome, TaskPriority.IMPORTANT, DATE_FORMATTER.parseDateTime("2012-06-11"), null)); persist( prepareTask( 3L, "Ask Claudia about project progress", atWork, TaskPriority.NORMAL, DATE_FORMATTER.parseDateTime("2012-06-15"), null)); persist( prepareTask( 4L, "Call to Tom Simson for help", inbox, TaskPriority.NORMAL, DATE_FORMATTER.parseDateTime("2012-06-12"), TIME_FORMATTER.parseDateTime("14:00"))); }
private static Slice dateFormat( ISOChronology chronology, Locale locale, long timestamp, Slice formatString) { DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString).withChronology(chronology).withLocale(locale); return Slices.copiedBuffer(formatter.print(timestamp), Charsets.UTF_8); }
private long parseDateTime(String value, DateTimeZone timeZone) { // first check for timestamp if (value.length() > 4 && StringUtils.isNumeric(value)) { try { long time = Long.parseLong(value); return timeUnit.toMillis(time); } catch (NumberFormatException e) { throw new ElasticsearchParseException( "failed to parse date field [" + value + "] as timestamp", e); } } DateTimeFormatter parser = dateTimeFormatter.parser(); if (timeZone != null) { parser = parser.withZone(timeZone); } try { return parser.parseMillis(value); } catch (IllegalArgumentException e) { throw new ElasticsearchParseException( "failed to parse date field [" + value + "] with format [" + dateTimeFormatter.format() + "]", e); } }
public FidoDevice updateFidoDevice(String id, FidoDevice fidoDevice) throws Exception { fidoDeviceService = FidoDeviceService.instance(); GluuCustomFidoDevice gluuCustomFidoDevice = fidoDeviceService.getGluuCustomFidoDeviceById(fidoDevice.getUserId(), id); if (gluuCustomFidoDevice == null) { throw new EntryPersistenceException( "Scim2FidoDeviceService.updateFidoDevice(): Resource " + id + " not found"); } GluuCustomFidoDevice updatedGluuCustomFidoDevice = CopyUtils2.updateGluuCustomFidoDevice(fidoDevice, gluuCustomFidoDevice); log.info(" Setting meta: update device "); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC(); // Date should be in UTC format Date dateLastModified = DateTime.now().toDate(); updatedGluuCustomFidoDevice.setMetaLastModified( dateTimeFormatter.print(dateLastModified.getTime())); if (updatedGluuCustomFidoDevice.getMetaLocation() == null || (updatedGluuCustomFidoDevice.getMetaLocation() != null && updatedGluuCustomFidoDevice.getMetaLocation().isEmpty())) { String relativeLocation = "/scim/v2/FidoDevices/" + id; updatedGluuCustomFidoDevice.setMetaLocation(relativeLocation); } fidoDeviceService.updateGluuCustomFidoDevice(gluuCustomFidoDevice); FidoDevice updatedFidoDevice = CopyUtils2.copy(gluuCustomFidoDevice, new FidoDevice()); return updatedFidoDevice; }
public static String getWeekRange(String dateCode) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy/MM/dd"); DateTimeFormatter outformatter = DateTimeFormat.forPattern("dd.MM"); DateTime endWeek = formatter.parseDateTime(dateCode); DateTime startWeek = endWeek.minusDays(6); return outformatter.print(startWeek) + "-" + outformatter.print(endWeek); }
public static String getLastDayOfLastMonth(int month) { LocalDate endOfLastMonth = new LocalDate(getYear(), month, 1); endOfLastMonth = endOfLastMonth.minusDays(1); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy/MM/dd"); // System.out.println(dateFormatter.print(endOfLastMonth)); return dateFormatter.print(endOfLastMonth); }
public static String getLastDayOfMounth(int month) { LocalDate startOfNextMonth = new LocalDate(getYear(), month, 1); startOfNextMonth = startOfNextMonth.dayOfMonth().withMaximumValue(); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy/MM/dd"); // System.out.println(dateFormatter.print(startOfNextMonth)); return dateFormatter.print(startOfNextMonth); }
/** * Returns the pattern used by a particular style and locale. * * <p>The first character is the date style, and the second character is the time style. Specify a * character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full. A date or * time may be ommitted by specifying a style character '-'. * * @param style two characters from the set {"S", "M", "L", "F", "-"} * @param locale locale to use, null means default * @return the formatter * @throws IllegalArgumentException if the style is invalid * @since 1.3 */ public static String patternForStyle(String style, LocaleInfo locale) { DateTimeFormatter formatter = createFormatterForStyle(style); if (locale == null) { locale = LocaleInfo.getCurrentLocale(); } // Not pretty, but it works. return ((StyleFormatter) formatter.getPrinter()).getPattern(locale); }
@Override public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) { DateTime time = new DateTime().withHourOfDay(hourOfDay).withMinuteOfHour(minute); DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("h:mm a"); inviteTime.setText(timeFormatter.print(time)); creator.getInvite().time = time.getMillis(); }
public static String getYesterdayDate() { Date date = new Date(); DateTime dt = new DateTime(date); dt = dt.minusDays(1); // DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy/MM/dd"); return dateFormatter.print(dt); }
@Override public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) { DateTime date = new DateTime().withDate(year, monthOfYear + 1, dayOfMonth); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("E, MMMM d"); inviteDate.setText(dateFormatter.print(date)); creator.getInvite().date = date.getMillis(); }
@RequestMapping("/importacao") public ModelAndView importacao(Model model) { logger.info("===> importacao"); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/YYYY"); DateTime hoje = DateTime.now(); model.addAttribute("dataEnvio", fmt.print(hoje)); return new ModelAndView("pedido/importacao"); }
// Iterate through data and if tuple datetime is within window pass to the x/y arrays // Returns nothing, but gets x/y arrays for the Regression calculations public void getArrays() throws SQLException { String dateObjectString; DateTime dateObject; DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); DateTime queryTimeObject = format.parseDateTime(queryTime); Double tupDateMS = null; Double tupValue = null; // Initialize arrays List<Double> xValuesAL = new ArrayList<Double>(); // The X values of the data set points 'datetime List<Double> yValuesAL = new ArrayList<Double>(); // The Y values of the data set points 'value'; // GET DATA // prepare cnx vars in data object dataObject.prepareCNXVariables(startDate, endDate, sensorID); // build query based on interpolation dataObject.updateQuery(rows, startDate, endDate, sensorID, queryTime); // get data from map ResultSet data = dataObject.getData(); // check tuples to make sure there is tuple before and after querytime checkTuples(data); // ITERATE OVER RESULT SET AND ADD TO ARRAY LIST dates and VALUES // Loop through RS and fetch the tuple values before and after querytime Integer rowCount = getRowCount(data); if (data.first()) { // make sure there is 1 tuple for either: before and on/after OR after and on/before if ((preTup == 1 && (postTup == 1 || sameTup == 1)) || (postTup == 1 && (preTup == 1 || sameTup == 1))) { for (int i = 0; i < rowCount; i++) { dateObjectString = data.getString("datetime"); String valueString = data.getString("value"); Double valueDouble = Double.parseDouble(valueString); if (dateObjectString.endsWith(".0")) { dateObjectString = dateObjectString.substring(0, dateObjectString.length() - 2); } dateObject = format.parseDateTime(dateObjectString); double dateMS = dateObject.getMillis(); tupDateMS = dateMS; tupValue = valueDouble; // Add before and after values to ArrayList xValuesAL.add(tupDateMS); yValuesAL.add(tupValue); data.next(); } } else { System.out.println("\nAdjust queryTime to be within temporal field window"); } } // Converts ArrayList into actual Array to be used by calculation. // This will be useful if I restructure so window can be number of rows. xValues = new Double[xValuesAL.size()]; for (int i = 0; i < xValuesAL.size(); i++) xValues[i] = xValuesAL.get(i); yValues = new Double[yValuesAL.size()]; for (int i = 0; i < yValuesAL.size(); i++) yValues[i] = yValuesAL.get(i); }