List of usage examples for org.joda.time DateTime getYear
public int getYear()
From source file:com.linkedin.cubert.utils.FileSystemUtils.java
License:Open Source License
public static List<Path> getDurationPaths(FileSystem fs, Path root, DateTime startDate, DateTime endDate, boolean isDaily, int hourStep, boolean errorOnMissing, boolean useHourlyForMissingDaily) throws IOException { List<Path> paths = new ArrayList<Path>(); while (endDate.compareTo(startDate) >= 0) { Path loc;//from ww w.ja v a 2s . c om if (isDaily) loc = generateDatedPath(root, endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth()); else loc = generateDatedPath(root, endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth(), endDate.getHourOfDay()); // Check that directory exists, and contains avro files. if (fs.exists(loc) && fs.globStatus(new Path(loc, "*" + "avro")).length > 0) { paths.add(loc); } else { loc = generateDatedPath(new Path(root.getParent(), "hourly"), endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth()); if (isDaily && useHourlyForMissingDaily && fs.exists(loc)) { for (FileStatus hour : fs.listStatus(loc)) { paths.add(hour.getPath()); } } else if (errorOnMissing) { throw new RuntimeException("Missing directory " + loc.toString()); } } if (hourStep == 24) endDate = endDate.minusDays(1); else endDate = endDate.minusHours(hourStep); } return paths; }
From source file:com.manydesigns.portofino.calendar.AbstractMonthView.java
License:Open Source License
public AbstractMonthView(DateTime referenceDateTime, int firstDayOfWeek) { logger.debug("Initializing month"); this.referenceDateTime = referenceDateTime; logger.debug("Reference date time: {}", referenceDateTime); this.firstDayOfWeek = firstDayOfWeek; logger.debug("First day of week: {}", firstDayOfWeek); referenceDateMidnight = new DateMidnight(referenceDateTime); referenceYear = referenceDateTime.getYear(); referenceMonth = referenceDateTime.getMonthOfYear(); monthStart = referenceDateMidnight.withDayOfMonth(1); monthEnd = monthStart.plusMonths(1); monthInterval = new Interval(monthStart, monthEnd); monthViewStart = monthStart.withDayOfWeek(firstDayOfWeek); monthViewEnd = monthViewStart.plusWeeks(6); monthViewInterval = new Interval(monthViewStart, monthViewEnd); logger.debug("Month view start: {}", monthViewStart); logger.debug("Initializing weeks"); weeks = createWeeksArray(6);/*from w ww .j a v a 2 s . c om*/ DateMidnight weekStart = monthViewStart; for (int i = 0; i < weeks.length; i++) { DateMidnight weekEnd = weekStart.plusWeeks(1); weeks[i] = createWeek(weekStart, weekEnd); weekStart = weekEnd; } }
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
License:Open Source License
@Override public List<TherapySurgeryReportElementDto> getTherapySurgeryReportElements(@Nonnull final String patientId, final Double patientHeight, @Nonnull final DateTime searchStart, @Nonnull final RoundsIntervalDto roundsIntervalDto, @Nonnull final Locale locale, @Nonnull final DateTime when) { Preconditions.checkNotNull(patientId, "patientId"); Preconditions.checkNotNull(searchStart, "searchStart"); Preconditions.checkNotNull(roundsIntervalDto, "roundsIntervalDto"); Preconditions.checkNotNull(locale, "locale"); Preconditions.checkNotNull(when, "when"); final DateTime roundsStart = new DateTime(searchStart.getYear(), searchStart.getMonthOfYear(), searchStart.getDayOfMonth(), roundsIntervalDto.getStartHour(), roundsIntervalDto.getStartMinute()); final List<Pair<MedicationOrderComposition, MedicationInstructionInstruction>> instructionsList = medicationsOpenEhrDao .findMedicationInstructions(patientId, Intervals.infiniteFrom(roundsStart), null); final Double referenceWeight = medicationsOpenEhrDao.getPatientLastReferenceWeight(patientId, Intervals.infiniteTo(searchStart)); final List<TherapySurgeryReportElementDto> elements = new ArrayList<>(); final Map<Long, MedicationDataForTherapyDto> medicationsMap = getMedicationDataForTherapies( instructionsList, null);// w ww. j a v a 2s . c o m for (final Pair<MedicationOrderComposition, MedicationInstructionInstruction> instructionPair : instructionsList) { final MedicationOrderComposition composition = instructionPair.getFirst(); final MedicationInstructionInstruction instruction = instructionPair.getSecond(); final MedicationTimingCluster medicationTiming = instruction.getOrder().get(0).getMedicationTiming(); final Interval instructionInterval = MedicationsEhrUtils.getInstructionInterval(medicationTiming); final boolean onlyOnce = isOnlyOnceThenEx(medicationTiming); if (instructionInterval.overlaps(Intervals.infiniteFrom(searchStart)) || onlyOnce && instructionInterval.getStart().isAfter(searchStart.minusHours(1))) { final List<MedicationActionAction> actions = MedicationsEhrUtils.getInstructionActions(composition, instruction); if (!isTherapyCanceledAbortedOrSuspended(actions)) { final TherapyDto therapy = getTherapyFromMedicationInstruction(composition, instruction, referenceWeight, patientHeight, when); therapyDisplayProvider.fillDisplayValues(therapy, false, true, false, locale, true); final boolean containsAntibiotics = getMedicationIds( MedicationsEhrUtils.getRepresentingOrderActivity(instruction)).stream().anyMatch( id -> medicationsMap.containsKey(id) && medicationsMap.get(id).isAntibiotic()); if (containsAntibiotics) { final int consecutiveDays = getTherapyConsecutiveDay( getOriginalTherapyStart(patientId, composition), when, when, therapy.getPastDaysOfTherapy()); elements.add(new TherapySurgeryReportElementDto(therapy.getFormattedTherapyDisplay(), consecutiveDays)); } else { elements.add(new TherapySurgeryReportElementDto(therapy.getFormattedTherapyDisplay())); } } } } return elements; }
From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskCreatorImpl.java
License:Open Source License
private List<NewTaskRequestDto> createTasks(final Long patientId, final MedicationOrderComposition composition, final MedicationInstructionInstruction instruction, final AdministrationTimingDto administrationTiming, final RoundsIntervalDto roundsInterval, final List<Interval> tasksCreationIntervals, final boolean therapyStart, final DateTime lastTaskTimestamp) { final boolean simple = MedicationsEhrUtils.isSimpleInstruction(instruction); final boolean variable = MedicationsEhrUtils.isVariableInstruction(instruction); final boolean variableDays = MedicationsEhrUtils.isVariableDaysInstruction(instruction); String linkedTherapyId = null; //last task triggers task creation for linked therapy final Pair<MedicationOrderComposition, MedicationInstructionInstruction> instructionPair = Pair .of(composition, instruction); for (final MedicationInstructionInstruction inst : composition.getMedicationDetail() .getMedicationInstruction()) { if (medicationsBo.doesInstructionHaveLinkToCompareInstruction(inst, instructionPair, OpenEhrLinkType.ISSUE)) { linkedTherapyId = InstructionTranslator.translate(inst, composition); break; }/* w ww .j a v a 2 s .c o m*/ } final List<NewTaskRequestDto> taskRequests = new ArrayList<>(); for (final Interval interval : tasksCreationIntervals) { if (variableDays) { final Map<DateTime, TherapyDoseDto> administrationDateTimesMap = new HashMap<>(); for (final OrderActivity orderActivity : instruction.getOrder()) { final TherapyDoseDto dose = getTherapyDoseDto(orderActivity, simple); if (dose != null) { final DvTime dvTime = orderActivity.getMedicationTiming().getTiming().getTime().get(0); final DvDate dvDate = orderActivity.getMedicationTiming().getTiming().getDate().get(0); final Pair<Integer, Integer> parsedTime = DvUtils.getHourMinute(dvTime); final DateTime parsedDate = ISODateTimeFormat.date().parseDateTime(dvDate.getValue()); administrationDateTimesMap.put( new DateTime(parsedDate.getYear(), parsedDate.getMonthOfYear(), parsedDate.getDayOfMonth(), parsedTime.getFirst(), parsedTime.getSecond()), dose); } } final List<NewTaskRequestDto> tasks = createTasksForVariableDaysTherapy(patientId, instruction, composition.getUid().getValue(), interval, administrationDateTimesMap, therapyStart); taskRequests.addAll(tasks); } else if (variable) { final Map<HourMinuteDto, TherapyDoseDto> administrationTimesMap = new HashMap<>(); for (final OrderActivity orderActivity : instruction.getOrder()) { final TherapyDoseDto dose = getTherapyDoseDto(orderActivity, simple); final Pair<Integer, Integer> parsedTime = DvUtils .getHourMinute(orderActivity.getMedicationTiming().getTiming().getTime().get(0)); administrationTimesMap.put(new HourMinuteDto(parsedTime.getFirst(), parsedTime.getSecond()), dose); } final List<NewTaskRequestDto> tasks = createTasksForVariableTherapy(patientId, instruction, composition.getUid().getValue(), interval, administrationTimesMap, therapyStart); taskRequests.addAll(tasks); } else { final TherapyDoseDto dose = getTherapyDoseDto(instruction.getOrder().get(0), simple); final List<NewTaskRequestDto> tasks = createTasksForConstantTherapy(patientId, instruction, composition.getUid().getValue(), interval, dose, administrationTiming, roundsInterval, therapyStart, lastTaskTimestamp, linkedTherapyId); taskRequests.addAll(tasks); } } return taskRequests; }
From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskCreatorImpl.java
License:Open Source License
private DateTime combine(final DateTime fromTime, final HourMinuteDto hourMinuteDto) { return new DateTime(fromTime.getYear(), fromTime.getMonthOfYear(), fromTime.getDayOfMonth(), hourMinuteDto.getHour(), hourMinuteDto.getMinute()); }
From source file:com.mastfrog.acteur.headers.DateTimeHeader.java
License:Open Source License
@Override public DateTime toValue(String value) { long val = 0; if (val == 0) { try {/*from w w w . jav a 2 s .c o m*/ val = Headers.ISO2822DateFormat.parseDateTime(value).getMillis(); } catch (IllegalArgumentException e) { try { //Sigh...use java.util.date to handle "GMT", "PST", "EST" val = Date.parse(value); } catch (IllegalArgumentException ex) { new IllegalArgumentException(value, ex).printStackTrace(); return null; } } } DateTime result = new DateTime(val, DateTimeZone.UTC); //to be truly compliant, accept 2-digit dates if (result.getYear() < 100 && result.getYear() > 0) { if (result.getYear() >= 50) { result = result.withYear(2000 - (100 - result.getYear())).withDayOfYear(result.getDayOfYear() - 1); //don't ask } else { result = result.withYear(2000 + result.getYear()); } } return result; }
From source file:com.money.manager.ex.recurring.transactions.RecurringTransactionEditActivity.java
License:Open Source License
private void initializePaymentDateSelector() { if (mViewHolder.paymentDateTextView == null) return;//from w w w.jav a2 s .co m DateTime paymentDate = getRecurringTransaction().getPaymentDate(); mViewHolder.paymentDateTextView.setText(paymentDate.toString(Constants.LONG_DATE_PATTERN)); // mViewHolder.paymentDateTextView.setTag(paymentDate.toString(Constants.ISO_DATE_FORMAT)); mViewHolder.paymentDateTextView.setOnClickListener(new View.OnClickListener() { CalendarDatePickerDialogFragment.OnDateSetListener listener = new CalendarDatePickerDialogFragment.OnDateSetListener() { @Override public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) { DateTime dateTime = MmxDateTimeUtils.from(year, monthOfYear + 1, dayOfMonth); setPaymentDate(dateTime); } }; @Override public void onClick(View v) { // Show calendar with the current date selected. DateTime dateTime = getPaymentDate(); CalendarDatePickerDialogFragment datePicker = new CalendarDatePickerDialogFragment() .setFirstDayOfWeek(MmxDateTimeUtils.getFirstDayOfWeek()).setOnDateSetListener(listener) .setPreselectedDate(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth()); if (new UIHelper(RecurringTransactionEditActivity.this).isDarkTheme()) { datePicker.setThemeDark(); } datePicker.show(getSupportFragmentManager(), TAG_DATEPICKER); } }); mViewHolder.paymentPreviousDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DateTime dateTime = getPaymentDate().minusDays(1); setPaymentDate(dateTime); } }); mViewHolder.paymentNextDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DateTime dateTime = getPaymentDate().plusDays(1); setPaymentDate(dateTime); } }); }
From source file:com.money.manager.ex.search.OnDateButtonClickListener.java
License:Open Source License
@Override public void onClick(View v) { DateTime dateTime = MmxDateTimeUtils.today(); String calendarValue = mTextView.getText().toString(); if (!TextUtils.isEmpty(calendarValue)) { String userDatePattern = new MmxDateTimeUtils(mParent.getApplicationContext()).getUserDatePattern(); DateTimeFormatter formatter = DateTimeFormat.forPattern(userDatePattern); dateTime = formatter.parseDateTime(calendarValue); }// w w w . j a v a 2 s . c o m CalendarDatePickerDialogFragment datePicker = new CalendarDatePickerDialogFragment() .setFirstDayOfWeek(MmxDateTimeUtils.getFirstDayOfWeek()).setOnDateSetListener(mDateSetListener) .setPreselectedDate(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth()); if (new UIHelper(mParent).isDarkTheme()) { datePicker.setThemeDark(); } datePicker.show(mParent.getSupportFragmentManager(), DATEPICKER_TAG); }
From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java
License:Open Source License
/** * Due Date picker/*from w w w .j av a2s . c om*/ */ public void initDateSelector() { DateTime date = this.transactionEntity.getDate(); if (date == null) { date = DateTime.now(); transactionEntity.setDate(date); } showDate(date); viewHolder.dateTextView.setOnClickListener(new View.OnClickListener() { CalendarDatePickerDialogFragment.OnDateSetListener listener = new CalendarDatePickerDialogFragment.OnDateSetListener() { @Override public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) { DateTime dateTime = MmxDateTimeUtils.from(year, monthOfYear + 1, dayOfMonth); setDate(dateTime); } }; @Override public void onClick(View v) { DateTime dateTime = transactionEntity.getDate(); CalendarDatePickerDialogFragment datePicker = new CalendarDatePickerDialogFragment() .setOnDateSetListener(listener).setFirstDayOfWeek(MmxDateTimeUtils.getFirstDayOfWeek()) .setPreselectedDate(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth()); if (new UIHelper(getContext()).isDarkTheme()) { datePicker.setThemeDark(); } datePicker.show(mParent.getSupportFragmentManager(), DATEPICKER_TAG); } }); viewHolder.previousDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DateTime dateTime = transactionEntity.getDate().minusDays(1); setDate(dateTime); } }); viewHolder.nextDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { DateTime dateTime = transactionEntity.getDate().plusDays(1); setDate(dateTime); } }); }
From source file:com.money.manager.ex.utils.MmxDateTimeUtils.java
License:Open Source License
public static void setDatePicker(DateTime date, DatePicker datePicker) { datePicker.updateDate(date.getYear(), date.getMonthOfYear() - 1, date.getDayOfMonth()); }