List of usage examples for org.joda.time DateMidnight now
public static DateMidnight now()
ISOChronology
in the default time zone. From source file:com.ehdev.chronos.lib.types.holders.PayPeriodHolder.java
License:Open Source License
/** * Will do the calculations for the start and end of the process *///from www .j av a 2 s . com public void generate() { //Get the start and end of pay period DateTime startOfPP = gJob.getStartOfPayPeriod(); gDuration = gJob.getDuration(); DateTime endOfPP = DateTime.now(); //Today long duration = endOfPP.getMillis() - startOfPP.getMillis(); DateTimeZone startZone = startOfPP.getZone(); DateTimeZone endZone = endOfPP.getZone(); long offset = endZone.getOffset(endOfPP) - startZone.getOffset(startOfPP); int weeks = (int) ((duration + offset) / 1000 / 60 / 60 / 24 / 7); /* System.out.println("end of pp: " + endOfPP); System.out.println("start of pp: " + startOfPP); System.out.println("dur: " + duration); System.out.println("weeks diff: " + weeks); */ switch (gDuration) { case ONE_WEEK: //weeks = weeks; startOfPP = startOfPP.plusWeeks(weeks); endOfPP = startOfPP.plusWeeks(1); break; case TWO_WEEKS: weeks = weeks / 2; startOfPP = startOfPP.plusWeeks(weeks * 2); endOfPP = startOfPP.plusWeeks(2); break; case THREE_WEEKS: weeks = weeks / 3; startOfPP = startOfPP.plusWeeks(weeks * 3); endOfPP = startOfPP.plusWeeks(3); break; case FOUR_WEEKS: weeks = weeks / 4; startOfPP = startOfPP.plusWeeks(weeks * 4); endOfPP = startOfPP.plusWeeks(4); break; case FULL_MONTH: //in this case, endOfPP is equal to now startOfPP = DateMidnight.now().toDateTime().withDayOfMonth(1); endOfPP = startOfPP.plusMonths(1); break; case FIRST_FIFTEENTH: DateTime now = DateTime.now(); if (now.getDayOfMonth() >= 15) { startOfPP = now.withDayOfMonth(15); endOfPP = startOfPP.plusDays(20).withDayOfMonth(1); } else { startOfPP = now.withDayOfMonth(1); endOfPP = now.withDayOfMonth(15); } break; default: break; } if (startOfPP.isAfter(DateTime.now())) { startOfPP = startOfPP.minusWeeks(getDays() / 7); endOfPP = endOfPP.minusWeeks(getDays() / 7); } gStartOfPP = startOfPP; gEndOfPP = endOfPP; }
From source file:net.mklew.hotelms.persistance.hibernate.configuration.DbBootstrap.java
private void bootstrap() { logger.debug("Started bootstrapping database"); Session session = hibernateSessionFactory.getCurrentSession(); // bootstrapping data Collection<RoomType> types = new ArrayList<>(); RoomType luxury = new RoomType("luxury"); RoomType cheap = new RoomType("cheap"); RoomType niceOne = new RoomType("nice one"); types.addAll(Arrays.asList(luxury, cheap, niceOne)); Collection<Room> rooms; Money standardPrice = Money.parse("USD 100"); Money upchargeExtraPerson = Money.parse("USD 110"); Money upchargeExtraBed = Money.parse("USD 120"); // RackRate rackRate = new RackRate(standardPrice, upchargeExtraPerson, upchargeExtraBed, null); // RackRate rackRate1 = new RackRate(standardPrice.plus(10), upchargeExtraPerson.plus(10), // upchargeExtraBed.plus(10), null); // RackRate rackRate2 = new RackRate(standardPrice.plus(20), upchargeExtraPerson.plus(20), // upchargeExtraBed.plus(20), null); // RackRate rackRate3 = new RackRate(standardPrice.plus(30), upchargeExtraPerson.plus(30), // upchargeExtraBed.plus(30), null); // RackRate rackRate4 = new RackRate(standardPrice.plus(40), upchargeExtraPerson.plus(40), // upchargeExtraBed.plus(40), null); // RackRate rackRate5 = new RackRate(standardPrice.plus(50), upchargeExtraPerson.plus(50), // upchargeExtraBed.plus(50), null); Room L100 = new Room("L", new RoomName("100"), luxury, HousekeepingStatus.CLEAN, RoomAvailability.AVAILABLE, 1, new Occupancy(3, 4), standardPrice, upchargeExtraPerson, upchargeExtraBed); Room L101 = new Room("L", new RoomName("101"), luxury, HousekeepingStatus.CLEAN, RoomAvailability.AVAILABLE, 1, new Occupancy(2, 3), standardPrice.plus(10), upchargeExtraPerson.plus(10), upchargeExtraBed.plus(10));//from w w w . j ava 2 s .co m Room L102 = new Room("L", new RoomName("102"), luxury, HousekeepingStatus.CLEAN, RoomAvailability.OCCUPIED, 3, new Occupancy(2, 4), standardPrice.plus(30), upchargeExtraPerson.plus(30), upchargeExtraBed.plus(30)); Room C103 = new Room("C", new RoomName("103"), cheap, HousekeepingStatus.CLEAN, RoomAvailability.AVAILABLE, 4, new Occupancy(4, 10), standardPrice.plus(30), upchargeExtraPerson.plus(30), upchargeExtraBed.plus(30)); Room C104 = new Room("C", new RoomName("104"), cheap, HousekeepingStatus.CLEAN, RoomAvailability.AVAILABLE, 5, new Occupancy(6, 12), standardPrice.plus(40), upchargeExtraPerson.plus(40), upchargeExtraBed.plus(40)); Room N105 = new Room("N", new RoomName("105"), niceOne, HousekeepingStatus.CLEAN, RoomAvailability.AVAILABLE, 2, new Occupancy(2, 5), standardPrice.plus(50), upchargeExtraPerson.plus(50), upchargeExtraBed.plus(50)); rooms = Arrays.asList(L100, L101, L102, C103, C104, N105); Collection<Rate> rates; Season season = new BasicSeason("winter special", new AvailabilityPeriod(DateTime.now(), DateTime.now().plusDays(90), true)); Season season2 = new BasicSeason("christmas special", new AvailabilityPeriod(DateTime.now(), DateTime.now().plusDays(30), true)); Rate rate1_L100 = new SeasonRate(Money.parse("USD 50"), Money.parse("USD 60"), Money.parse("USD 70"), L100, season); Rate rate2_L100 = new SeasonRate(Money.parse("USD 20"), Money.parse("USD 60"), Money.parse("USD 70"), L100, season2); Rate rate1_L101 = new SeasonRate(Money.parse("USD 60"), Money.parse("USD 70"), Money.parse("USD 60"), L101, season); Rate rate2_L101 = new SeasonRate(Money.parse("USD 20"), Money.parse("USD 70"), Money.parse("USD 60"), L101, season2); Rate rate1_L102 = new SeasonRate(Money.parse("USD 60"), Money.parse("USD 70"), Money.parse("USD 60"), L102, season); Rate rate2_L102 = new SeasonRate(Money.parse("USD 20"), Money.parse("USD 70"), Money.parse("USD 60"), L102, season2); Rate rate1_C103 = new SeasonRate(Money.parse("USD 40"), Money.parse("USD 70"), Money.parse("USD 60"), C103, season); Rate rate2_C103 = new SeasonRate(Money.parse("USD 30"), Money.parse("USD 70"), Money.parse("USD 60"), C103, season2); Rate rate1_C104 = new SeasonRate(Money.parse("USD 70"), Money.parse("USD 70"), Money.parse("USD 60"), C104, season); Rate rate2_C104 = new SeasonRate(Money.parse("USD 50"), Money.parse("USD 70"), Money.parse("USD 60"), C104, season2); Rate rate1_N105 = new SeasonRate(Money.parse("USD 80"), Money.parse("USD 70"), Money.parse("USD 60"), N105, season); Rate rate2_N105 = new SeasonRate(Money.parse("USD 90"), Money.parse("USD 70"), Money.parse("USD 60"), N105, season2); Collection<Season> seasons = Arrays.asList(season, season2); rates = Arrays.asList(rate1_L100, rate2_L100, rate1_L101, rate2_L101, rate1_L102, rate2_L102, rate1_C103, rate2_C103, rate1_C104, rate2_C104, rate1_N105, rate2_N105); Guest guest1 = new Guest("Mr", "John", "Doe", Gender.MALE, DocumentType.DRIVER_LICENSE, "Drivers123", "555123123"); Guest guest2 = new Guest("Mr", "Johnson", "Donnel", Gender.MALE, DocumentType.DRIVER_LICENSE, "DRI123", "555555123"); Guest guest3 = new Guest("Mr", "Johnathan", "Doougles", Gender.MALE, DocumentType.DRIVER_LICENSE, "DDRI1555", "555123123"); Guest guest4 = new Guest("Miss", "Joana", "Dooues", Gender.FEMALE, DocumentType.PERSONAL_ID, "APK132555", "819238923"); Guest guest5 = new Guest("Ms", "Kate", "Hudson", Gender.FEMALE, DocumentType.PERSONAL_ID, "DSA123889", "534098123"); Guest guest6 = new Guest("Mr", "Jack", "Hack", Gender.MALE, DocumentType.PERSONAL_ID, "LKK123555", "123589124"); Guest guest7 = new Guest("Ms", "Ewa", "Kowalska", Gender.FEMALE, DocumentType.PERSONAL_ID, "PAS123553", "123985332"); Guest guest8 = new Guest("Ms", "Karolina", "Iksinska", Gender.FEMALE, DocumentType.DRIVER_LICENSE, "DRI132511", "898123532"); Guest guest9 = new Guest("Mr", "Grzegorz", "Brzeczyszczykiewicz", Gender.MALE, DocumentType.PERSONAL_ID, "AAA123123", "342089123"); Guest guest10 = new Guest("Mrs", "John", "ToBeRemoved", Gender.MALE, DocumentType.DRIVER_LICENSE, "DRI132135", "12312353"); Guest guest11 = new Guest("Mr", "John", "ToBeRemoved1", Gender.MALE, DocumentType.DRIVER_LICENSE, "DRI132136", "12312353"); Guest guest12 = new Guest("Mr", "John", "ToBeRemoved2", Gender.MALE, DocumentType.DRIVER_LICENSE, "DRI132137", "12312353"); Guest guest13 = new Guest("Mr", "John", "ToBeRemoved3", Gender.MALE, DocumentType.DRIVER_LICENSE, "DRI132138", "12312353"); Guest guest14 = new Guest("Mr", "John", "ToBeRemoved4", Gender.MALE, DocumentType.DRIVER_LICENSE, "DRI132139", "12312353"); Guest guest15 = new Guest("Mr", "John", "ToBeRemoved5", Gender.MALE, DocumentType.DRIVER_LICENSE, "DRI132110", "12312353"); Collection<Guest> guests = Arrays.asList(guest1, guest2, guest3, guest4, guest5, guest6, guest7, guest8, guest9, guest10, guest11, guest12, guest13, guest14, guest15); for (Guest guest : guests) { guest.setNationality("Polish"); } Reservation reservation = new Reservation(Id.NO_ID, guest1, L100.rackRate(), new DateTime(new DateMidnight(2012, 12, 1)), new DateTime(new DateMidnight(2012, 12, 5)), 2, 0, 0, ReservationStatus.INHOUSE); Reservation reservation2 = new Reservation(Id.NO_ID, guest2, L102.rackRate(), new DateTime(new DateMidnight(2012, 12, 3)), new DateTime(new DateMidnight(2012, 12, 8)), 2, 0, 0, ReservationStatus.RESERVED); Reservation reservation3 = new Reservation(Id.NO_ID, guest2, rate1_C103, new DateTime(new DateMidnight(2012, 12, 2)), new DateTime(new DateMidnight(2012, 12, 15)), 3, 0, 0, ReservationStatus.RESERVED); Reservation reservation4 = new Reservation(Id.NO_ID, guest3, rate1_N105, new DateTime(new DateMidnight(2012, 12, 10)), new DateTime(new DateMidnight(2012, 12, 14)), 2, 0, 0, ReservationStatus.RESERVED); Reservation reservation5 = new Reservation(Id.NO_ID, guest5, rate2_C104, new DateTime(new DateMidnight(2012, 12, 20)), new DateTime(new DateMidnight(2012, 12, 28)), 1, 0, 0, ReservationStatus.RESERVED); Reservation reservation6 = new Reservation(Id.NO_ID, guest5, rate2_C104, new DateTime(DateMidnight.now().plusDays(1)), new DateTime(DateMidnight.now().plusDays(5)), 1, 0, 0, ReservationStatus.RESERVED); Reservation reservation7 = new Reservation(Id.NO_ID, guest1, rate1_C103, new DateTime(DateMidnight.now()), new DateTime(DateMidnight.now().plusDays(5)), 1, 0, 0, ReservationStatus.CHECKIN); Reservation reservation71 = new Reservation(Id.NO_ID, guest6, rate1_N105, new DateTime(DateMidnight.now().minusDays(3)), new DateTime(DateMidnight.now()), 1, 0, 0, ReservationStatus.CHECKOUT); Reservation reservation8 = new Reservation(Id.NO_ID, guest7, L102.rackRate(), new DateTime(DateMidnight.now().minusDays(5)), new DateTime(DateMidnight.now().minusDays(2)), 1, 0, 0, ReservationStatus.HISTORY); Reservation reservation9 = new Reservation(Id.NO_ID, guest8, rate2_C104, new DateTime(DateMidnight.now().plusDays(6)), new DateTime(DateMidnight.now().plusDays(9)), 1, 0, 0, ReservationStatus.RESERVED); Reservation reservation10 = new Reservation(Id.NO_ID, guest3, L100.rackRate(), new DateTime(DateMidnight.now().minusDays(2)), new DateTime(DateMidnight.now().plusDays(9)), 1, 0, 0, ReservationStatus.INHOUSE); Collection<Reservation> reservations = Arrays.asList(reservation, reservation2, reservation3, reservation4, reservation5, reservation6, reservation7, reservation8, reservation9, reservation71, reservation10); L100.setAvailability(RoomAvailability.OCCUPIED); N105.setAvailability(RoomAvailability.OCCUPIED); C103.setAvailability(RoomAvailability.OCCUPIED); // bootstrapping data session.beginTransaction(); logger.debug("adding room types:"); for (RoomType type : types) { session.save(type); logger.debug("room type: " + type.toString()); } logger.debug("adding rooms"); for (Room room : rooms) { logger.debug("room: " + room.toString()); session.save(room); } logger.debug("adding seasons"); for (Season s : seasons) { logger.debug("season: " + s.toString()); session.save(s); } logger.debug("adding season rates"); for (Rate rate : rates) { logger.debug("rate: " + rate.toString()); session.save(rate); } logger.debug("adding guests"); for (Guest guest : guests) { logger.debug("guest: " + guest.toString()); session.save(guest); } logger.debug("adding reservations"); for (Reservation res : reservations) { logger.debug("reservation: " + res.toString()); session.save(res); } session.getTransaction().commit(); logger.debug("Finished bootstrapping database"); }
From source file:net.sourceforge.atunes.gui.javafx.AboutDialogController.java
License:Open Source License
/** * Gets the license text./* w w w .j a va 2 s . c o m*/ * * @return the license text */ private String getLicenseText() { return StringUtils.getString("Copyright (C) 2006-", DateMidnight.now().year().get(), " The aTunes Team\n\n", "This program is free software; you can redistribute it and/or ", "modify it under the terms of the GNU General Public License ", "as published by the Free Software Foundation; either version 2 ", "of the License, or (at your option) any later version.\n\n", "This program is distributed in the hope that it will be useful, ", "but WITHOUT ANY WARRANTY; without even the implied warranty of ", "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ", "GNU General Public License for more details.\n\n", "You should have received a copy of the GNU General Public License ", "along with this program; if not, write to the\n\nFree Software ", "Foundation, Inc.\n51 Franklin Street, Fifth Floor\nBoston, MA\n02110-1301, USA"); }
From source file:org.key2gym.business.services.AttendancesServiceBean.java
License:Apache License
@Override public List<AttendanceDTO> findAttendancesByDate(DateMidnight date) throws SecurityViolationException { /*//from w w w . ja va 2 s . com * Arguments validation. */ if (date == null) { throw new NullPointerException("The date is null."); //NOI18N } if (!date.equals(DateMidnight.now()) && !callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityException(getString("Security.Access.Denied")); } List<Attendance> attendances = getEntityManager() .createNamedQuery("Attendance.findByDatetimeBeginRangeOrderByDateTimeBeginDesc") //NOI18N .setParameter("low", date.toDate()) //NOI18N .setParameter("high", date.plusDays(1).toDate()) //NOI18N .getResultList(); List<AttendanceDTO> result = new LinkedList<AttendanceDTO>(); for (Attendance attendance : attendances) { result.add(wrapAttendance(attendance)); } return result; }
From source file:org.key2gym.business.services.CashServiceBean.java
License:Apache License
@Override public BigDecimal getCashByDate(DateMidnight date) throws SecurityViolationException { if (date == null) { throw new NullPointerException("The date is null."); //NOI18N }//w w w .j a v a 2 s . co m if (!date.equals(DateMidnight.now())) { if (!callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Access.Denied")); } } else { if (!callerHasAnyRole(SecurityRoles.JUNIOR_ADMINISTRATOR, SecurityRoles.SENIOR_ADMINISTRATOR)) { throw new SecurityViolationException(getString("Security.Access.Denied")); } } BigDecimal cash = (BigDecimal) em.createNamedQuery("OrderEntity.sumPaymentsForDateRecorded") //NOI18N .setParameter("dateRecorded", date.toDate()) //NOI18N .getSingleResult(); /* * The sum aggregate function returns null, when there is not * any orders. */ if (cash == null) { cash = BigDecimal.ZERO; } CashAdjustment adjustment = em.find(CashAdjustment.class, date.toDate()); if (adjustment != null) { cash = cash.add(adjustment.getAmount()); } return cash; }
From source file:org.key2gym.business.services.OrdersServiceBean.java
License:Apache License
@Override public List<OrderDTO> findAllByDate(DateMidnight date) throws SecurityViolationException { if (date == null) { throw new NullPointerException("The begin is null."); //NOI18N }//w ww .java 2s .c o m if (!DateMidnight.now().equals(date) && !callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Access.Denied")); } List<OrderEntity> orders = em.createNamedQuery("OrderEntity.findByDateRecordedOrderByIdDesc") //NOI18N .setParameter("dateRecorded", date.toDate()) //NOI18N .getResultList(); List<OrderDTO> result = new LinkedList<OrderDTO>(); for (OrderEntity order : orders) { result.add(wrapOrderEntity(order)); } return result; }
From source file:org.key2gym.business.services.OrdersServiceBean.java
License:Apache License
@Override public BigDecimal getTotalForDate(DateMidnight date) throws SecurityViolationException { if (date == null) { throw new NullPointerException("The date is null."); //NOI18N }/*from w w w . j a v a 2 s . c o m*/ if (!DateMidnight.now().equals(date) && !callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Access.Denied")); } BigDecimal result = (BigDecimal) em.createNamedQuery("OrderEntity.sumPaymentsForDateRecorded") //NOI18N .setParameter("dateRecorded", date.toDate()) //NOI18N .getSingleResult(); if (result == null) { result = BigDecimal.ZERO; } return result.setScale(2); }
From source file:org.key2gym.client.highlighters.ExpirationDateHighlighter.java
License:Apache License
/** * Updates the component's highlight./*from ww w . ja v a 2s.c o m*/ */ @Override protected ColorScheme getHighlightModelFor(String text) { DateMidnight value; try { value = DateMidnight.parse(text, DateTimeFormat.forPattern("dd-MM-yyyy")); } catch (IllegalArgumentException ex) { value = null; } if (value == null) { return NULL_SCHEME; } int daysTillExpiration = Days.daysBetween(DateMidnight.now(), value).getDays(); if (daysTillExpiration > 2) { return NOT_SOON_SCHEME; } else if (daysTillExpiration > 0) { return SOON_SCHEME; } else { return PASSED_SCHEME; } }
From source file:rapture.kernel.ScheduleApiImpl.java
License:Open Source License
private TimedEventRecord getEventRecordForJob(CallingContext context, String jobUri) { RaptureJob job = retrieveJob(context, jobUri); CronParser parser = MultiCronParser.create(job.getCronSpec()); DateTime midnight = DateMidnight.now().toDateTime(DateTimeZone.forID(job.getTimeZone())); DateTime nextRunDate = parser.nextRunDate(midnight); if (nextRunDate != null) { TimedEventRecord record = new TimedEventRecord(); record.setEventName(job.getDescription()); record.setEventContext(jobUri);/*from w w w. ja v a2 s .c o m*/ record.setInfoContext(job.getActivated().toString()); record.setWhen(nextRunDate.toDate()); return record; } else { return null; } }