List of usage examples for org.joda.time LocalDateTime plusHours
public LocalDateTime plusHours(int hours)
From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java
License:Open Source License
public void addToField(Granulaarsus field, int value) { if (field == Granulaarsus.MINUTE || field == Granulaarsus.HOUR_OF_HALF_DAY || field == Granulaarsus.HOUR_OF_DAY) { // Put date and time together LocalDateTime ajaFookus = getAsLocalDateTime(); // perform operation if (field == Granulaarsus.MINUTE) { ajaFookus = ajaFookus.plusMinutes(value); this.underlyingTime = ajaFookus.toLocalTime(); this.underlyingDate = ajaFookus.toLocalDate(); if (dateModified) { updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION); }//from w w w . j a v a2 s.c om updateTimeRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; } if (field == Granulaarsus.HOUR_OF_DAY || field == Granulaarsus.HOUR_OF_HALF_DAY) { ajaFookus = ajaFookus.plusHours(value); this.underlyingTime = ajaFookus.toLocalTime(); this.underlyingDate = ajaFookus.toLocalDate(); if (dateModified) { updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION); } updateTimeRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; } } if (field == Granulaarsus.DAY_OF_MONTH) { this.underlyingDate = (this.underlyingDate).plusDays(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.DAY_OF_WEEK) { this.underlyingDate = (this.underlyingDate).plusDays(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.WEEK_OF_YEAR) { this.underlyingDate = (this.underlyingDate).plusWeeks(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.MONTH) { this.underlyingDate = (this.underlyingDate).plusMonths(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.YEAR) { this.underlyingDate = (this.underlyingDate).plusYears(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.YEAR_OF_CENTURY) { // NB! Toimib nagu tavalise aastaarvu muutmine this.underlyingDate = (this.underlyingDate).plusYears(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.CENTURY_OF_ERA) { this.underlyingDate = (this.underlyingDate).plusYears(value * 100); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } }
From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java
License:Open Source License
public void seekField(Granulaarsus field, int direction, String soughtValue, boolean excludingCurrent) { // --------------------------------- // PART OF DAY // --------------------------------- if (field == Granulaarsus.TIME && soughtValue != null && soughtValue.matches("(NI|MO|AF|EV)") && direction != 0) { int dir = (direction > 0) ? (1) : (-1); // Loome k2esolevat ajafookust t2ielikult kirjeldava objekti LocalDateTime ajaFookus = getAsLocalDateTime(); // AlgneMargend ehk p2evaosa, millest peame ennem m66da saama, kuni v6ime uue // v22rtuse omaks v6tta String algneMargend = (excludingCurrent) ? (SemLeidmiseAbimeetodid.getPartOfDay(ajaFookus.toLocalTime())) : (null);/* w ww . j a va2 s .c o m*/ if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale tunnile ajaFookus = ajaFookus.plusHours(dir * (-1)); } int count = 0; while (true) { LocalDateTime uusFookus = ajaFookus.plusHours(1 * dir); ajaFookus = uusFookus; String newPartOfDay = SemLeidmiseAbimeetodid.getPartOfDay(uusFookus.toLocalTime()); if (algneMargend != null) { if (algneMargend.equals(newPartOfDay)) { continue; } else { algneMargend = null; } } if (newPartOfDay != null && newPartOfDay.equals(soughtValue)) { algneMargend = newPartOfDay; count++; if (count == Math.abs(direction)) { break; } } } this.partOfDay = soughtValue; updateTimeRepresentation(Granulaarsus.TIME, soughtValue, true, ADD_TYPE_OPERATION); this.underlyingTime = ajaFookus.toLocalTime(); this.underlyingDate = ajaFookus.toLocalDate(); functionOtherThanSetUsed = true; } // --------------------------------- // WORKDAY OR WEEKEND // --------------------------------- if (field == Granulaarsus.DAY_OF_WEEK && soughtValue != null && soughtValue.matches("(WD|WE)") && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne p2ev ehk p2ev, millest tahame tingimata m66duda String algneMargend = (excludingCurrent) ? (SemLeidmiseAbimeetodid.getWordDayOrWeekend(ajaFookus)) : (null); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale ajaFookus = ajaFookus.plusDays(dir * (-1)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir); ajaFookus = nihutatudFookus; String toopaevVoiNadalalopp = SemLeidmiseAbimeetodid.getWordDayOrWeekend(ajaFookus); if (algneMargend != null) { if (algneMargend.equals(toopaevVoiNadalalopp)) { continue; } else { algneMargend = null; } } if (toopaevVoiNadalalopp.equals(soughtValue)) { algneMargend = toopaevVoiNadalalopp; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; (this.openedFields).put(VALUE_FIELD.DAY, soughtValue); updateDateRepresentation(Granulaarsus.DAY_OF_WEEK, soughtValue, true, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } // --------------------------------- // SEASONs // --------------------------------- if (field == Granulaarsus.MONTH && soughtValue != null && soughtValue.matches("(SP|SU|FA|WI)") && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne aastaaeg ehk aastaaeg, millest tahame tingimata m66duda String algneMargend = (excludingCurrent) ? (SemLeidmiseAbimeetodid.getSeason(ajaFookus)) : (null); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule ajaFookus = ajaFookus.plusMonths(dir * (-1)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir); ajaFookus = nihutatudFookus; String aastaaeg = SemLeidmiseAbimeetodid.getSeason(ajaFookus); if (algneMargend != null) { if (algneMargend.equals(aastaaeg)) { continue; } else { algneMargend = null; } } if (aastaaeg.equals(soughtValue)) { algneMargend = aastaaeg; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; // Detsembri puhul liigume j2rgmisesse aastasse (st - talve loetakse aasta algusest) ... if ((this.underlyingDate).getMonthOfYear() == DateTimeConstants.DECEMBER) { this.underlyingDate = (this.underlyingDate).plusMonths(1); } openedFields.put(VALUE_FIELD.MONTH_OR_WEEK, soughtValue); updateDateRepresentation(Granulaarsus.MONTH, soughtValue, true, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } // --------------------------------- // QUARTERs // --------------------------------- if (field == Granulaarsus.MONTH && soughtValue != null && soughtValue.matches("Q(1|2|3|4)") && direction != 0) { int dir = (direction > 0) ? (1) : (-1); LocalDate ajaFookus = new LocalDate(this.underlyingDate); // Algne kvartal ehk kvartal, millest tahame tingimata m66duda String algneMargend = (excludingCurrent) ? (SemLeidmiseAbimeetodid.getQuarterOfYear(ajaFookus)) : (null); if (!excludingCurrent) { // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule ajaFookus = ajaFookus.plusMonths(dir * (-1)); } int count = 0; while (true) { LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir); ajaFookus = nihutatudFookus; String kvartal = SemLeidmiseAbimeetodid.getQuarterOfYear(ajaFookus); if (algneMargend != null) { if (algneMargend.equals(kvartal)) { continue; } else { algneMargend = null; } } if (kvartal.equals(soughtValue)) { algneMargend = kvartal; count++; if (count == Math.abs(direction)) { break; } } } this.underlyingDate = ajaFookus; String newQuarterVal = SemLeidmiseAbimeetodid.getQuarterOfYear(this.underlyingDate); openedFields.put(VALUE_FIELD.MONTH_OR_WEEK, newQuarterVal); updateDateRepresentation(Granulaarsus.MONTH, newQuarterVal, true, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; this.dateModified = true; } }
From source file:org.jtwig.functions.builtin.DateFunctions.java
License:Apache License
private Date modify(String modifyString, LocalDateTime localDateTime) throws FunctionException { LocalDateTime result;/*from w ww .j a va 2 s .com*/ Matcher matcher = compile(MODIFY_PATTERN).matcher(modifyString); matcher.find(); int signal = 1; if (matcher.group(1).equals("-")) signal = -1; int val = Integer.valueOf(matcher.group(2)) * signal; String type = matcher.group(3).toLowerCase(); if (type.startsWith("day")) result = localDateTime.plusDays(val); else if (type.startsWith("month")) result = localDateTime.plusMonths(val); else if (type.startsWith("year")) result = localDateTime.plusYears(val); else if (type.startsWith("second")) result = localDateTime.plusSeconds(val); else if (type.startsWith("hour")) result = localDateTime.plusHours(val); else if (type.startsWith("minute")) result = localDateTime.plusMinutes(val); else throw new FunctionException("Unknown type " + matcher.group(3)); return result.toDate(); }
From source file:view.popups.shift.ShiftPanel.java
private void initButtons() { settingsButton = new SettingsButton(); settingsButton.setDisable(true);/*from w ww . j a v a2 s . c o m*/ settingsButton.setOnAction(e -> { configPanel.display("Foretag ndring"); }); dayShift = new ImageButton("pictures/morgen 60.png", "pictures/morgen 60 dark.png"); dayShift.setOnAction(e -> { eveningShift.setUnPressed(); nightShift.setUnPressed(); //For at finde datoen og tiden p ugen skal der lgges nogle elementer til. //Frst lgges dayOfWeek til en ny variabel d. S hvis det fx er onsdag er //dayOfWeek 3 og der lgges derfor 3-1 til mandagen som er dayOfWeek 1, //Dette gr at man for den dato som onsdagen ligger p. LocalDateTime d = startTime.plusDays(dayOfWeek - 1); //Dernst defineres starttidspunktet. Dagsvagter starter per default 8:30. d = d.plusHours(8); d = d.plusMinutes(30); shift = new TimeInvestment(DAY_HOURS, DAY_MINUTES, d, employee, null); settingsButton.setDisable(false); }); eveningShift = new ImageButton("pictures/aften 60.png", "pictures/aften 60 dark.png"); eveningShift.setOnAction(e -> { dayShift.setUnPressed(); nightShift.setUnPressed(); LocalDateTime d = startTime.plusDays(dayOfWeek - 1); d = d.plusHours(15); d = d.plusMinutes(15); shift = new TimeInvestment(DAY_HOURS, DAY_MINUTES, d, employee, null); settingsButton.setDisable(false); }); nightShift = new ImageButton("pictures/nat 60.png", "pictures/nat 60 dark.png"); nightShift.setOnAction(e -> { dayShift.setUnPressed(); eveningShift.setUnPressed(); int id = 1; LocalDateTime d = startTime.plusDays(dayOfWeek - 1); d = d.plusHours(23); d = d.plusMinutes(30); shift = new TimeInvestment(DAY_HOURS, DAY_MINUTES, d, employee, null); settingsButton.setDisable(false); }); configPanel.getChangeButton().setOnAction(e -> { makeChange(); }); }
From source file:view.schema.AssignedAllRoomsRow.java
public AssignedAllRoomsRow(String shiftName, LocalDateTime startTime, ArrayList<TimeInvestment> shifts, int startHour, int startMinute, int periodLengthHour, int periodLengthMinute) { this.shifts = shifts; this.startTime = startTime; shiftTypeLabel = new RoomTile(shiftName); this.setOrientation(Orientation.HORIZONTAL); this.getChildren().add(shiftTypeLabel); //Tilfj vagter til dagene p ugen. i0 = mandag, i4 = fredag. for (int i = 0; i < 5; i++) { LocalDateTime date = startTime.plusDays(i); date = date.withField(DateTimeFieldType.hourOfDay(), startHour); date = date.withField(DateTimeFieldType.minuteOfHour(), startMinute); //Nulstil sekunder og millisekunder (vigtigt). date = date.withSecondOfMinute(0); date = date.withMillisOfSecond(0); LocalDateTime endDate = new LocalDateTime(date); endDate = endDate.plusHours(periodLengthHour).plusMinutes(periodLengthMinute); ShiftTile shiftTile = new ShiftTile( Xray.getInstance().getTimeInvestmentControl().getShiftsInPeriod(shifts, date, endDate)); this.getChildren().add(shiftTile); }/*from w ww.j av a 2s . c om*/ }
From source file:view.schema.AssignedRoomRow.java
public AssignedRoomRow(Room room, ArrayList<TimeInvestment> shifts, LocalDateTime startTime, int startHour, int startMinute, int periodLengthHour, int periodLengthMinute) { this.startTime = startTime; this.room = room; this.shifts = shifts; roomLabel = new RoomTile(room.getRoomName()); //Tilfj rumnavn til venstre. this.getChildren().add(roomLabel); //Tilfj vagter til dagene p ugen. i0 = mandag, i4 = fredag. for (int i = 0; i < 5; i++) { LocalDateTime date = startTime.plusDays(i); date = date.withField(DateTimeFieldType.hourOfDay(), startHour); date = date.withField(DateTimeFieldType.minuteOfHour(), startMinute); //Nulstil sekunder og millisekunder (vigtigt). date = date.withSecondOfMinute(0); date = date.withMillisOfSecond(0); LocalDateTime endDate = new LocalDateTime(date); endDate = endDate.plusHours(periodLengthHour).plusMinutes(periodLengthMinute); ShiftTile shiftTile = new ShiftTile( Xray.getInstance().getTimeInvestmentControl().getShiftsInPeriod(shifts, date, endDate)); this.getChildren().add(shiftTile); }/*from w w w. j a v a 2 s. c om*/ }
From source file:view.schema.WeekendRow.java
public WeekendRow(String dayName, LocalDateTime date, ArrayList<TimeInvestment> shifts) { shifts = Xray.getInstance().getTimeInvestmentControl().getShiftsInPeriod(shifts, date, date.plusHours(23).plusMinutes(59)); LabelTile labelTile = new LabelTile(dayName); ShiftTile shiftTile = new ShiftTile(shifts); children.add(labelTile);/* w ww. j ava 2s . co m*/ children.add(shiftTile); }