List of usage examples for org.apache.commons.lang3.time DateUtils addDays
public static Date addDays(final Date date, final int amount)
From source file:com.todopl.foreign.msexchange.MSExchange.java
public static void main(String[] args) { try {/*from w ww . j av a 2 s .co m*/ Date from = new Date(); Date to = DateUtils.addDays(from, 5); System.out.println("Appointments from today " + from.toString()); Pair<String, FindItemsResults<Appointment>> result = getEvents(null, from, to, "USER", "PASS", "EMAIL"); System.out.println("This is your version: " + result.getLeft()); System.out.println("These are your appointments:"); System.out.println(); for (Appointment a : result.getRight().getItems()) { System.out.println("Subject==== " + a.getSubject()); System.out.println("From======= " + a.getStart()); System.out.println("To========= " + a.getEnd()); System.out.println("Id========= " + a.getId()); System.out.println(); } System.out.println("Now with the version filled in:"); Pair<String, FindItemsResults<Appointment>> result2 = getEvents(result.getLeft(), from, to, "USER", "PASSWD", "EMAIL"); System.out.println("This is your version: " + result2.getLeft().toString()); System.out.println("These are your appointments:"); System.out.println(); for (Appointment a : result2.getRight().getItems()) { System.out.println("Subject==== " + a.getSubject()); System.out.println("From======= " + a.getStart()); System.out.println("To========= " + a.getEnd()); System.out.println(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.google.api.services.samples.analytics.cmdline.CoreReportingApiReferenceSample.java
/** * Main demo. This first initializes an Analytics service object. It then queries for the top 25 * organic search keywords and traffic sources by visits. Finally each important part of the * response is printed to the screen.// w w w. j av a2s.c o m * * @param args command line args. */ public static void main(String[] args) { try { if (args.length == 2) { // Start and end date are supplied startDate = new SimpleDateFormat("yyyy-MM-dd").parse(args[0]); endDate = new SimpleDateFormat("yyyy-MM-dd").parse(args[1]); } System.out.println("Retrieving for dates " + startDate + " " + endDate); HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); Analytics analytics = initializeAnalytics(); MongoClient mongo = new MongoClient("localhost", 27017); DB regus_analytics_db = mongo.getDB("regus_analytics"); DBCollection regus_visited_companies = regus_analytics_db.getCollection("ga"); DBCollection regus_visit_attributes = regus_analytics_db.getCollection("visit_attrs"); DBCollection centerMapping = regus_analytics_db.getCollection("center_mapping"); GaData gaData; for (Date d = startDate; !DateUtils.isSameDay(d, DateUtils.addDays(endDate, 1)); d = DateUtils .addDays(d, 1)) { int startIndex = 0; do { System.out.println("Executing data query for visited companies for date: " + d); gaData = executeDataQueryForVisitedCompanies(analytics, TABLE_ID, startIndex, d); insertVisitedCompaniesData(gaData, regus_visited_companies, d); startIndex = gaData.getQuery().getStartIndex() + gaData.getQuery().getMaxResults(); } while (gaData.getNextLink() != null && !gaData.getNextLink().isEmpty()); startIndex = 0; do { System.out.println("Executing data query for visit attributes for date: " + d); gaData = executeDataQueryForVisitAttributes(analytics, TABLE_ID, startIndex, d); insertVisitAttributesData(gaData, regus_visit_attributes, d, centerMapping); startIndex = gaData.getQuery().getStartIndex() + gaData.getQuery().getMaxResults(); } while (gaData.getNextLink() != null && !gaData.getNextLink().isEmpty()); } } catch (GoogleJsonResponseException e) { System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:com.tala.enterprise.talabank.commons.DateManager.java
public static boolean hasExpired(Date startDate, int days) { return new Date().after(DateUtils.addDays(startDate, days)); }
From source file:com.tala.enterprise.talabank.commons.DateManager.java
public static Date addDays(Date startDate, int days) { return DateUtils.addDays(startDate, days); }
From source file:com.francetelecom.clara.cloud.commons.DateHelper.java
/** * get now with e delta of nbDay//from ww w . ja va 2s . c o m * @param nbDay delta day number (could be negative) * @return altered date */ public static Date getDateDeltaDay(int nbDay) { Date now = getNow(); Date deltaDate = DateUtils.addDays(now, nbDay); return deltaDate; }
From source file:com.alibaba.utils.date.CommonDateUtils.java
/** * <pre>// w ww .j a v a 2 s .co m * * : * 2013.09.202 * 2013.09.18, 2013.09.19, 2013.09.20 * </pre> * @param currentDate * @param days * @return */ public static List<Date> beforeCurrentDate(Date currentDate, int days) { List<Date> dateList = new ArrayList<Date>(); // 0. if (currentDate == null) { return null; } if (days <= 0) { dateList.add(DateUtils.truncate(currentDate, Calendar.DAY_OF_MONTH)); return dateList; } // 1. Date startDate = DateUtils.addDays(currentDate, 0 - days); for (int i = 0; i < days; ++i) { Date date = DateUtils.addDays(startDate, i); // dateList.add(DateUtils.truncate(date, Calendar.DAY_OF_MONTH)); } // 2. dateList.add(DateUtils.truncate(currentDate, Calendar.DAY_OF_MONTH)); return dateList; }
From source file:com.ekom.ekomerp.global.DateTimeUtils.java
public static Date getLastDayOfWeek(Date date) { return DateUtils.addDays(getFirstDayOfWeek(date), 6); }
From source file:eu.ggnet.dwoss.misc.op.itest.ResolveRepaymentBeanITHelper.java
public void generateLines(int amount) { for (int i = 0; i < amount; i++) { ReportLine makeReportLine = generator.makeReportLine(Arrays.asList(TradeName.AMAZON), DateUtils.addDays(new Date(), -30), 25); makeReportLine.setPositionType(PositionType.UNIT); makeReportLine.setDocumentType(DocumentType.ANNULATION_INVOICE); reportLineEao.getEntityManager().persist(makeReportLine); }/*w ww . j a v a 2 s. c om*/ }
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * * Get or return Past or Future date based on parameter</p> * <p>/*from ww w . j a va 2 s.co m*/ * <b>Parameter amount :</b> use negative symbol to get past date, use * positive symbol to get future date. Parameter amount combination with * parameter constantParameter. </p> * <p> * <b>Parameter constantParameter :</b> the type of times that will be * added. Example : CommonUtilConstant.DATE_FORMAT_MONTH</p> * <p> * <b>ConstantParameter type :</b></p> * <ul> * <li>CommonUtilConstant.DATE_FORMAT_MILLISECOND = millisecond</li> * <li>CommonUtilConstant.DATE_FORMAT_SECOND = second</li> * <li>CommonUtilConstant.DATE_FORMAT_MINUTES = minutes</li> * <li>CommonUtilConstant.DATE_FORMAT_HOURS = hours</li> * <li>CommonUtilConstant.DATE_FORMAT_DAY = day</li> * <li>CommonUtilConstant.DATE_FORMAT_WEEK = week</li> * <li>CommonUtilConstant.DATE_FORMAT_MONTH = month</li> * <li>CommonUtilConstant.DATE_FORMAT_YEAR = year</li> * </ul> * * @return Date type of past or future date * @param inputParam Date reference to calculate * @param timeDifference Integer reference, can be negative value like -7 or * positive value like 7 * @param constantParameter String reference,see the CommonUtilConstant */ public static Date getDateFrom(Date inputParam, int timeDifference, String constantParameter) { Date returnDate = null; if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_DAY)) { returnDate = DateUtils.addDays(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_HOURS)) { returnDate = DateUtils.addHours(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MILLISECOND)) { returnDate = DateUtils.addMilliseconds(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MINUTES)) { returnDate = DateUtils.addMinutes(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MONTH)) { returnDate = DateUtils.addMonths(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_SECOND)) { returnDate = DateUtils.addSeconds(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_YEAR)) { returnDate = DateUtils.addYears(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_WEEK)) { returnDate = DateUtils.addWeeks(inputParam, timeDifference); } return returnDate; }
From source file:gaffer.example.gettingstarted.generator.DataGenerator8.java
@Override public Element getElement(final String line) { final String[] t = line.split(","); final Edge.Builder edgeBuilder = new Edge.Builder().group("data").source(t[0]).dest(t[1]).directed(true) .property("visibility", t[3]).property("count", 1L); final Date startDate; try {//w w w .ja v a2s . com startDate = DateUtils.truncate(new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(t[2]), Calendar.DAY_OF_MONTH); edgeBuilder.property("startDate", startDate).property("endDate", DateUtils.addDays(startDate, 1)); } catch (ParseException e) { throw new IllegalArgumentException("Unable to parse date", e); } return edgeBuilder.build(); }