List of usage examples for org.joda.time DateTime get
public int get(DateTimeFieldType type)
From source file:org.datavec.api.transform.transform.time.DeriveColumnsFromTimeTransform.java
License:Apache License
@Override public List<Writable> map(List<Writable> writables) { if (writables.size() != inputSchema.numColumns()) { throw new IllegalStateException("Cannot execute transform: input writables list length (" + writables.size() + ") does not " + "match expected number of elements (schema: " + inputSchema.numColumns() + "). Transform = " + toString()); }/*from w w w . j a v a 2 s .co m*/ int i = 0; Writable source = writables.get(deriveFromIdx); List<Writable> list = new ArrayList<>(writables.size() + derivedColumns.size()); for (Writable w : writables) { list.add(w); if (i++ == insertAfterIdx) { for (DerivedColumn d : derivedColumns) { switch (d.columnType) { case String: list.add(new Text(d.dateTimeFormatter.print(source.toLong()))); break; case Integer: DateTime dt = new DateTime(source.toLong(), inputTimeZone); list.add(new IntWritable(dt.get(d.fieldType))); break; default: throw new IllegalStateException("Unexpected column type: " + d.columnType); } } } } return list; }
From source file:org.datavec.api.transform.transform.time.DeriveColumnsFromTimeTransform.java
License:Apache License
/** * Transform an object/*from w ww . j a va 2s . co m*/ * in to another object * * @param input the record to transform * @return the transformed writable */ @Override public Object map(Object input) { List<Object> ret = new ArrayList<>(); Long l = (Long) input; for (DerivedColumn d : derivedColumns) { switch (d.columnType) { case String: ret.add(d.dateTimeFormatter.print(l)); break; case Integer: DateTime dt = new DateTime(l, inputTimeZone); ret.add(dt.get(d.fieldType)); break; default: throw new IllegalStateException("Unexpected column type: " + d.columnType); } } return ret; }
From source file:org.flockdata.transform.Dates.java
License:Open Source License
/** * As above, but using a custom delimiter *//*from w w w. j a va 2s .c o m*/ public static Object get(String dateColumn, String delimiter, String portion, ContentModel contentModel, Map<String, Object> data) { Long dateResult = ExpressionHelper.parseDate(contentModel.getColumnDef(dateColumn), data.get(dateColumn).toString()); DateTime dateTime = new DateTime(dateResult); String[] fields = portion.split(delimiter); String result = null; for (String field : fields) { if (field.equalsIgnoreCase("year")) result = addToResult(result, delimiter, Integer.toString(dateTime.get(DateTimeFieldType.year()))); else if (field.equalsIgnoreCase("month")) result = addToResult(result, delimiter, String.format("%02d", dateTime.get(DateTimeFieldType.monthOfYear()))); else if (field.equalsIgnoreCase("dom")) result = addToResult(result, delimiter, String.format("%02d", dateTime.get(DateTimeFieldType.dayOfMonth()))); else if (field.equalsIgnoreCase("dow")) result = addToResult(result, delimiter, String.format("%02d", dateTime.get(DateTimeFieldType.dayOfWeek()))); else if (field.equalsIgnoreCase("hour")) result = addToResult(result, delimiter, String.format("%02d", dateTime.get(DateTimeFieldType.hourOfDay()))); } return result; }
From source file:org.hepaces.surveyfeedbacktestscript.KrogerFeedbackManager.java
/** * Fills in the date and time fields/*w w w. ja va 2 s . c o m*/ * @param date * @param browser */ public static void fillInDateAndTime(DateTime date, WebDriver browser) { logger.debug("Attempting to fill in the date and time inputs @:" + browser.getCurrentUrl()); try { //Date Inputs WebElement monthInput = browser.findElement(By.id(inputMonthId)); WebElement dayInput = browser.findElement(By.id(inputDayId)); WebElement yearInput = browser.findElement(By.id(inputYearId)); //Time Inputs WebElement hourInput = browser.findElement(By.id(inputHourId)); WebElement minuteInput = browser.findElement(By.id(inputMinuteId)); WebElement amPmInput = browser.findElement(By.id(inputAMPM)); //handle date inputs (year is prepopulated, so not handled) numericDropDownHandler(date.getMonthOfYear(), monthInput); numericDropDownHandler(date.getDayOfMonth(), dayInput); //handle time inputs numericDropDownHandler(date.get(DateTimeFieldType.clockhourOfHalfday()), hourInput); numericDropDownHandler(date.getMinuteOfHour(), minuteInput); numericDropDownHandler(date.get(DateTimeFieldType.halfdayOfDay()) + 1, amPmInput); } catch (Exception e) { } }
From source file:org.kuali.kpme.core.util.TKUtils.java
License:Educational Community License
public static boolean isVirtualWorkDay(DateTime beginPeriodDateTime) { return (beginPeriodDateTime.getHourOfDay() != 0 || beginPeriodDateTime.getMinuteOfHour() != 0 && beginPeriodDateTime.get(DateTimeFieldType.halfdayOfDay()) != DateTimeConstants.AM); }
From source file:org.powertac.logtool.example.MktPriceStats.java
License:Apache License
@Override public void report() { for (Map.Entry<Integer, ClearedTrade[]> entry : data.entrySet()) { String delim = ""; if (!omitHeaders) { // add ts,dow,hod, DateTime dt = timeslotRepo.getDateTimeForIndex(entry.getKey()); output.format("%d,%d,%d,", entry.getKey(), dt.get(DateTimeFieldType.dayOfWeek()), dt.get(DateTimeFieldType.hourOfDay())); }//from w w w. j a v a 2 s . c o m ClearedTrade[] trades = entry.getValue(); if (trades.length != 24) log.error("short array " + trades.length); for (int i = 0; i < trades.length; i++) { if (null == trades[i]) { output.print(delim + "[0.0 0.0]"); } else { output.format("%s[%.4f %.4f]", delim, trades[i].getExecutionMWh(), trades[i].getExecutionPrice()); } delim = ","; } output.println(); } output.close(); }
From source file:org.schors.evlampia.search.SearchManager.java
License:Open Source License
public void init(Directory d) { this.directory = d; searcher = Searcher.create(directory); indexer = new LuceneIndexer(); DateTime dt = new DateTime(); int hours = dt.get(DateTimeFieldType.hourOfDay()); EvaExecutors.getInstance().getScheduler().scheduleAtFixedRate(new Runnable() { @Override/*from w ww . jav a 2 s .c o m*/ public void run() { vbotDAOHTMLImplementation.getInstance().flush(); try { SearchManager.getInstanse().updateIndex(true); } catch (IOException e) { log.error(e, e); } } }, 24 - hours, 24, TimeUnit.HOURS); }
From source file:pt.ist.fenixedu.quc.ui.spring.controller.gep.inquiries.CreateQucInquiriesController.java
License:Open Source License
@Atomic(mode = TxMode.WRITE) private void createInquiries(ExecutionSemester executionSemester) { //setting dates do the past, so that the inquiries only be active when set through interface DateTime begin = new DateTime(); int dayOfMonth = begin.get(DateTimeFieldType.dayOfMonth()); DateTime end = begin.minusDays(dayOfMonth); begin = end.minusDays(dayOfMonth);/*from w w w.ja v a2 s . com*/ // Curricular inquiry CurricularCourseInquiryTemplate newCourseInquiryTemplate = new CurricularCourseInquiryTemplate(begin, end); newCourseInquiryTemplate.setExecutionPeriod(executionSemester); CurricularCourseInquiryTemplate previousCourseInquiryTemplate = CurricularCourseInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousCourseInquiryTemplate.getInquiryBlocksSet()) { newCourseInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Teachers inquiry StudentTeacherInquiryTemplate newStudentTeacherInquiryTemplate = new StudentTeacherInquiryTemplate(begin, end); newStudentTeacherInquiryTemplate.setExecutionPeriod(executionSemester); StudentTeacherInquiryTemplate previousStudentTeacherInquiryTemplate = StudentTeacherInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousStudentTeacherInquiryTemplate.getInquiryBlocksSet()) { newStudentTeacherInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Delegates inquiry DelegateInquiryTemplate newDelegateInquiryTemplate = new DelegateInquiryTemplate(begin, end); newDelegateInquiryTemplate.setExecutionPeriod(executionSemester); DelegateInquiryTemplate previousDelegateInquiryTemplate = DelegateInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousDelegateInquiryTemplate.getInquiryBlocksSet()) { newDelegateInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Teachers inquiry TeacherInquiryTemplate newTeacherInquiryTemplate = new TeacherInquiryTemplate(begin, end); newTeacherInquiryTemplate.setExecutionPeriod(executionSemester); TeacherInquiryTemplate previousTeacherInquiryTemplate = TeacherInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousTeacherInquiryTemplate.getInquiryBlocksSet()) { newTeacherInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Regents inquiry RegentInquiryTemplate newRegentInquiryTemplate = new RegentInquiryTemplate(begin, end); newRegentInquiryTemplate.setExecutionPeriod(executionSemester); RegentInquiryTemplate previousRegentInquiryTemplate = RegentInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousRegentInquiryTemplate.getInquiryBlocksSet()) { newRegentInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Coordinators inquiry CoordinatorInquiryTemplate newCoordinatorInquiryTemplate = new CoordinatorInquiryTemplate(begin, end, true); newCoordinatorInquiryTemplate.setExecutionPeriod(executionSemester); CoordinatorInquiryTemplate previousCoordinatorInquiryTemplate = CoordinatorInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousCoordinatorInquiryTemplate.getInquiryBlocksSet()) { newCoordinatorInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Results inquiry ResultsInquiryTemplate newResultsInquiryTemplate = new ResultsInquiryTemplate(); newResultsInquiryTemplate.setExecutionPeriod(executionSemester); ResultsInquiryTemplate previousResultsInquiryTemplate = ResultsInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousResultsInquiryTemplate.getInquiryBlocksSet()) { newResultsInquiryTemplate.addInquiryBlocks(inquiryBlock); } }
From source file:pt.ist.fenixWebFramework.rendererExtensions.DurationRenderer.java
License:Open Source License
private Calendar convertDateTimeToCalendar(DateTime dt) { Calendar calendar = Calendar.getInstance(); calendar.clear();//from w ww.j a va 2 s. c o m calendar.set(Calendar.HOUR_OF_DAY, dt.get(DateTimeFieldType.hourOfDay())); calendar.set(Calendar.MINUTE, dt.get(DateTimeFieldType.minuteOfHour())); calendar.set(Calendar.SECOND, dt.get(DateTimeFieldType.secondOfMinute())); return calendar; }
From source file:ru.touchin.templates.calendar.CalendarUtils.java
License:Apache License
@NonNull private static List<CalendarItem> fillCalendarTillCurrentDate(@NonNull final DateTime cleanStartDate, @NonNull final DateTime startDate) { DateTime temp = startDate; final List<CalendarItem> calendarItems = new ArrayList<>(); int shift = 0; final int firstDate = temp.getDayOfMonth() - 1; //?? - 1 ? // add first month header calendarItems.add(new CalendarHeaderItem(temp.getYear(), temp.get(DateTimeFieldType.monthOfYear()) - 1, shift, shift)); // is Month starts from 1 or 0 ? temp = temp.withDayOfMonth(1);/*from www . j a v a2 s . co m*/ shift += 1; final int firstDayInTheWeek = temp.getDayOfWeek() - 1; // check if first day is Monday. If not - add empty items. Otherwise do nothing if (firstDayInTheWeek != 0) { calendarItems.add(new CalendarEmptyItem(shift, shift + firstDayInTheWeek - 1)); } shift += firstDayInTheWeek; // add range with days before today calendarItems.add(new CalendarDayItem(temp.getMillis(), 1, shift, shift + firstDate - 1, ComparingToToday.BEFORE_TODAY)); shift += firstDate; // add today item temp = cleanStartDate; calendarItems .add(new CalendarDayItem(temp.getMillis(), firstDate + 1, shift, shift, ComparingToToday.TODAY)); //add empty items and header if current day the last day in the month if (temp.getDayOfMonth() == temp.dayOfMonth().getMaximumValue()) { addItemsIfCurrentDayTheLastDayInTheMonth(startDate, calendarItems); } return calendarItems; }