List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:com.sos.scheduler.model.objects.IntervalConstants.java
License:Apache License
public Interval getInterval() { DateTime from = new DateTime(); DateTime to = null;//from w w w . j a v a 2s. c om switch (this) { case CURRENT_DAY: from = from.minusMillis(from.getMillisOfDay()); to = from.plusDays(1); break; case CURRENT_WEEK: from = from.minusMillis(from.getMillisOfDay()).minusDays(from.getDayOfWeek()); to = from.plusWeeks(1); break; case REST_OF_DAY: to = from.minusMillis(from.getMillisOfDay()).plusDays(1); break; case NEXT_24H: to = from.plusDays(1); break; case NEXT_WEEK: to = from.plusWeeks(1); break; } return new Interval(from, to); }
From source file:com.sos.scheduler.model.objects.JSObjHolidays.java
License:Apache License
public boolean isHoliday(DateTime date) { DateTime from = JodaTools.getStartOfDay(date); List<DateTime> result = getHolidays(new Interval(from, from.plusDays(1))); return (result.size() == 0) ? false : true; }
From source file:com.sos.scheduler.model.objects.JSObjHolidays.java
License:Apache License
public DateTime getNextNonHoliday(DateTime date) { DateTime result = date; while (isHoliday(result)) { result = result.plusDays(1); }/*from ww w . j av a2s . c om*/ return result; }
From source file:com.sos.scheduler.model.objects.JSObjPeriod.java
License:Apache License
@Override public RunTimeElements getRunTimeElements(Interval timeRange) { RunTimeElements result = new RunTimeElements(timeRange); DateTime dt = getDtSingleStartOrNull(timeRange.getStart()); if (dt != null) { result = new RunTimeElements(timeRange); if (!timeRange.contains(dt)) dt = dt.plusDays(1); while (true) { if (!timeRange.contains(dt)) break; result.add(new RunTimeElement(dt, getWhenHoliday())); dt = dt.plusDays(1);// ww w. ja va 2 s . c om } // Collections.sort(result, DateTimeComparator.getInstance()); } return result; }
From source file:com.sos.scheduler.model.tools.RunTimeElements.java
License:Apache License
public RunTimeElements(DateTime baseDate) { super(DateTimeComparator.getInstance()); DateTime from = JodaTools.getStartOfDay(baseDate); this.timeRange = new Interval(from, from.plusDays(1)); }
From source file:com.splicemachine.derby.utils.SpliceDateFunctions.java
License:Apache License
/** * Implements the NEXT_DAY function// w ww.j av a 2 s. c om */ public static Date NEXT_DAY(Date source, String weekday) throws SQLException { if (source == null || weekday == null) return source; String lowerWeekday = weekday.toLowerCase(); if (!WEEK_DAY_MAP.containsKey(lowerWeekday)) { throw PublicAPI.wrapStandardException(ErrorState.LANG_INVALID_DAY.newException(weekday)); } DateTime dt = new DateTime(source); int increment = WEEK_DAY_MAP.get(lowerWeekday) - dt.getDayOfWeek() - 1; if (increment > 0) { return new Date(dt.plusDays(increment).getMillis()); } else { return new Date(dt.plusDays(7 + increment).getMillis()); } }
From source file:com.splout.db.examples.PageCountsDataGenerator.java
License:Apache License
public void generate(File namesFile, int days, File outFolder) throws IOException { if (outFolder.exists()) { FileUtils.deleteDirectory(outFolder); }//from w w w.jav a2s.c o m outFolder.mkdirs(); if (!namesFile.exists()) { throw new IllegalArgumentException("Provided names file doesn't exist (" + namesFile + ")"); } List<String> names = Files.readLines(namesFile, Charset.forName("UTF-8")); DateTime today = new DateTime(); DateTime someDaysBefore = today.minusDays(days); someDaysBefore = someDaysBefore.withMinuteOfHour(0); someDaysBefore = someDaysBefore.withSecondOfMinute(0); while (someDaysBefore.isBefore(today)) { for (int hour = 0; hour < 24; hour++) { someDaysBefore = someDaysBefore.withHourOfDay(hour); File currentFile = new File(outFolder, "pagecounts-" + format.print(someDaysBefore)); BufferedWriter writer = new BufferedWriter(new FileWriter(currentFile)); for (String name : names) { int pageviews = (int) (Math.random() * 10000) + 1; writer.write("en " + name + " " + pageviews + " 0" + "\n"); } writer.close(); } someDaysBefore = someDaysBefore.plusDays(1); } }
From source file:com.springsource.greenhouse.events.JdbcEventRepository.java
License:Apache License
@Transactional public List<EventSession> findSessionsOnDay(Long eventId, LocalDate day, Long attendeeId) { DateTimeZone eventTimeZone = DateTimeZone.forID( jdbcTemplate.queryForObject("select timezone from Event where id = ?", String.class, eventId)); DateTime dayStart = day.toDateTimeAtStartOfDay(eventTimeZone); DateTime dayEnd = dayStart.plusDays(1); return jdbcTemplate.query(SELECT_SESSIONS_ON_DAY, eventSessionMapper.list(), attendeeId, eventId, dayStart.toDate(), dayEnd.toDate()); }
From source file:com.startupbidder.dao.MockDataBuilder.java
private Listing prepareListing(UserVO owner, String name, Listing.State state, String category, int amount, int percentage, String mantra, String summary, String companyUrl, DateTime createdAt, DateTime modifiedAt, String logo_url, String address) { Listing bp = new Listing(); bp.id = id();// w w w . j av a2s. com bp.name = name; bp.summary = summary; bp.mantra = mantra; bp.owner = new Key<SBUser>(SBUser.class, owner.toKeyId()); bp.contactEmail = owner.getEmail(); bp.founders = getFounders(owner.getName()); bp.type = Listing.Type.COMPANY; bp.notes = "Mock listing.\n"; bp.askedForFunding = amount > 0; bp.suggestedAmount = amount; bp.suggestedPercentage = percentage; bp.category = category; bp.state = state; int hours = new Random().nextInt(500) + 80; DateTime createdTime = createdAt != null ? createdAt : new DateTime().minusHours(hours); if (modifiedAt != null) { bp.modified = modifiedAt.toDate(); } bp.created = createdTime.toDate(); switch (state) { case NEW: break; case POSTED: bp.posted = createdTime.plusHours(hours * 5 / 10).toDate(); break; case ACTIVE: case FROZEN: bp.posted = createdTime.plusHours(hours * 7 / 10).toDate(); bp.listedOn = createdTime.plusHours(hours * 4 / 10).toDate(); if (bp.askedForFunding) { bp.closingOn = createdTime.plusHours(hours * 4 / 10).plusDays(30).toDate(); } break; case WITHDRAWN: bp.posted = createdTime.plusHours(hours * 8 / 10).toDate(); bp.listedOn = createdTime.plusHours(hours * 6 / 10).toDate(); bp.closingOn = createdTime.plusHours(hours * 6 / 10).plusDays(30).toDate(); break; case CLOSED: hours = new Random().nextInt(500) + 33 * 24; createdTime = new DateTime().minusHours(hours); bp.created = createdTime.toDate(); bp.posted = createdTime.plusHours(24).toDate(); bp.listedOn = createdTime.plusHours(48).toDate(); bp.closingOn = createdTime.plusDays(32).toDate(); break; } GeocodeLocation location = null; if (address != null) { location = getGeocodedLocation(address); location.randomize(0.1); } if (location == null) { location = getRandomLocation(); location.randomize(0.001); } bp.address = location.address; bp.city = location.city; bp.usState = "USA".equals(location.country) ? location.state : null; bp.country = location.country; DtoToVoConverter.updateBriefAddress(bp); bp.latitude = location.latitude; bp.longitude = location.longitude; bp.videoUrl = getVideo(); bp.website = !StringUtils.isEmpty(companyUrl) ? companyUrl : getWebsite(); bp.answer1 = getQuote(); bp.answer2 = getQuote(); bp.answer3 = getQuote(); bp.answer4 = getQuote(); bp.answer5 = getQuote(); bp.answer6 = getQuote(); bp.answer7 = getQuote(); bp.answer8 = getQuote(); bp.answer9 = getQuote(); bp.answer10 = getQuoteWithNulls(); bp.answer11 = getQuoteWithNulls(); bp.answer12 = getQuoteWithNulls(); bp.answer13 = getQuoteWithNulls(); bp.answer14 = getQuoteWithNulls(); bp.answer15 = getQuoteWithNulls(); bp.answer16 = getQuoteWithNulls(); bp.answer17 = getQuoteWithNulls(); bp.answer18 = getQuoteWithNulls(); bp.answer19 = getQuoteWithNulls(); bp.answer20 = getQuoteWithNulls(); bp.answer21 = getQuoteWithNulls(); bp.answer22 = getQuoteWithNulls(); bp.answer23 = getQuoteWithNulls(); bp.answer24 = getQuoteWithNulls(); bp.answer25 = getQuoteWithNulls(); bp.answer26 = getQuoteWithNulls(); if (!StringUtils.isEmpty(logo_url)) { logo_url = logo_url.replaceAll("^https://", "http://"); logoUrls.put(bp.id, logo_url); } return bp; }
From source file:com.todoroo.andlib.utility.DateUtilities.java
License:Open Source License
/** * Add the specified amount of months to the given time.<br/> * The day of month will stay the same.<br/> * * @param time the base-time (in milliseconds) to which the amount of months is added * @param interval the amount of months to be added * @return the calculated time in milliseconds *//*from www. j a v a 2 s .com*/ public static long addCalendarMonthsToUnixtime(long time, int interval) { DateTime dt = new DateTime(time); DateTime result = dt.plusMonths(interval); // preserving java.util.date behavior int diff = dt.getDayOfMonth() - result.getDayOfMonth(); if (diff > 0) { result = result.plusDays(diff); } return result.getMillis(); }