Example usage for org.apache.commons.lang3.time DateUtils isSameDay

List of usage examples for org.apache.commons.lang3.time DateUtils isSameDay

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils isSameDay.

Prototype

public static boolean isSameDay(final Calendar cal1, final Calendar cal2) 

Source Link

Document

Checks if two calendar objects are on the same day ignoring time.

28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.

Usage

From source file:com.heren.turtle.server.utils.SampleDateUtils.java

public static void main(String[] args) {
    Date d1 = new Date();
    Date d2 = new Date();
    System.out.println(d1.after(d2));
    boolean sameDay = DateUtils.isSameDay(d1, d2);
    System.out.println(sameDay);/*from   w  w  w.j ava2 s. c o  m*/
    System.out.println(addDay("2016-11-16", 3));
}

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.//from   ww  w.  j  av  a 2 s .  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:common.util.DateUtil.java

public static boolean isCurrentWeek(Date fechainicio, Date fechafin, Date date) {
    return DateUtils.isSameDay(date, fechainicio) || DateUtils.isSameDay(date, fechafin)
            || (date.after(fechainicio) && date.before(fechafin));
}

From source file:SampleLang.java

public static void checkDate() throws InterruptedException, ParseException {
    //date1 created
    Date date1 = new Date();
    //Print the date and time at this instant
    System.out.println("The time right now is >>" + date1);
    //Thread sleep for 1000 ms
    Thread.currentThread().sleep(DateUtils.MILLIS_PER_MINUTE);
    //date2 created.
    Date date2 = new Date();
    //Check if date1 and date2 have the same day
    System.out.println("Is Same Day >> " + DateUtils.isSameDay(date1, date2));
    //Check if date1 and date2 have the same instance
    System.out.println("Is Same Instant >> " + DateUtils.isSameInstant(date1, date2));
    //Round the hour
    System.out.println("Date after rounding >>" + DateUtils.round(date1, Calendar.HOUR));
    //Truncate the hour
    System.out.println("Date after truncation >>" + DateUtils.truncate(date1, Calendar.HOUR));
    //Three dates in three different formats
    String[] dates = { "2005.03.24 11:03:26", "2005-03-24 11:03", "2005/03/24" };
    //Iterate over dates and parse strings to java.util.Date objects
    for (int i = 0; i < dates.length; i++) {
        Date parsedDate = DateUtils.parseDate(dates[i],
                new String[] { "yyyy/MM/dd", "yyyy.MM.dd HH:mm:ss", "yyyy-MM-dd HH:mm" });
        System.out.println("Parsed Date is >>" + parsedDate);
    }/*from  w w  w.j  a  va 2 s .  c om*/
    //Display date in HH:mm:ss format
    System.out.println("Now >>" + DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(System.currentTimeMillis()));
}

From source file:net.larry1123.elec.util.logger.FileManager.java

public static long getSplitTime() {
    long set = System.currentTimeMillis();
    try {/*w w  w .  j  a  v a2s . co  m*/
        Date currentTime = DateUtils.parseDate(getDateFormatFromMilli(System.currentTimeMillis()),
                DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern());
        Date currentSplit = DateUtils.parseDate(getDateFormatFromMilli(getConfig().getCurrentSplit()),
                DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern());
        Date test;
        switch (getConfig().getSplit()) {
        case HOUR:
            test = DateUtils.addHours(currentTime, 1);
            test = DateUtils.setMinutes(test, 0);
            test = DateUtils.setSeconds(test, 0);
            test = DateUtils.setMilliseconds(test, 0);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case DAY:
            if (!DateUtils.isSameDay(currentTime, currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case WEEK:
            test = DateUtils.ceiling(currentTime, Calendar.WEEK_OF_MONTH);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case MONTH:
            test = DateUtils.ceiling(currentTime, Calendar.MONTH);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case NONE:
        default:
            set = 0;
            break;
        }
    } catch (ParseException e) {
        set = 0;
    }
    return set;
}

From source file:com.dreamwork.service.SenderService.java

public void monitoring() throws InterruptedException {
    Thread.sleep(60000L);/*from  ww  w  . j a v  a 2  s  .c om*/
    SessionFactory factory = service.getFactory();
    Session session = factory.getCurrentSession();
    session.beginTransaction();
    List result = session.createQuery("from FutureMail").list();
    for (FutureMail mail : (List<FutureMail>) result) {

        boolean sameDay = DateUtils.isSameDay(new Date(), mail.getWhen());
        if (sameDay) {
            Thread ts = new Thread(new Sender(mail));
            ts.start();
            if (mail.isIsSend()) {
                session.save(mail);
            }

        }
    }
    session.getTransaction().commit();
    session.close();
}

From source file:dev.maisentito.suca.commands.SeenCommandHandler.java

@Override
public void handleCommand(MessageEvent event, String[] args) throws Throwable {
    synchronized (this) {
        if (mSeenUsers.containsKey(args[0].toLowerCase())) {
            SeenData seenData = mSeenUsers.get(args[0].toLowerCase());
            String formatted;/*from   w  w w . j a  v  a2 s  .  c  om*/

            if (DateUtils.isSameDay(seenData.time, new Date())) {
                formatted = DateFormatUtils.ISO_TIME_NO_T_TIME_ZONE_FORMAT.format(seenData.time);
            } else {
                formatted = DateFormatUtils.ISO_DATE_TIME_ZONE_FORMAT.format(seenData.time);
            }

            event.respond(String.format("seen: %s <%s> %s", formatted, seenData.nick, seenData.message));
        } else {
            event.respond("seen: user " + args[0] + " not seen");
        }
    }
}

From source file:br.ufg.inf.es.fs.contpatri.contpatri.model.InventarioTest.java

@Test
public void testarInventarioValido() {
    Inventario inventario = new Inventario(EMISSAO, mockGestor, listaBensSoUmItem);
    assertNull(inventario.getDataFechamento());
    Date dataFechamento = new Date();
    inventario.setDataFechamento(dataFechamento);
    assertEquals(EMISSAO, inventario.getDataEmissao());
    DateUtils.isSameDay(EMISSAO, inventario.getDataFechamento());
    assertTrue(inventario.getDataFechamento() != dataFechamento);
    assertEquals(mockGestor, inventario.getGestor());
    assertTrue(inventario.getAnalisados().contains(new Analise(b1, inventario, null)));
}

From source file:com.adaptris.core.event.LicenseExpiryWarningEvent.java

/** Get the expiry date as an actual Date object.
 * @return the expiry date./*from   ww  w .  j  av  a 2s .  co m*/
 */
public Date when() {
    Date result = (Date) expiryDate.clone();
    Date licenseExpiryDate = toDate(licenseExpiry);
    if (!DateUtils.isSameDay(expiryDate, licenseExpiryDate)) {
        // use the earlier date...
        result = (Date) min(expiryDate, licenseExpiryDate).clone();
    }
    return result;
}

From source file:br.ufg.inf.es.fs.contpatri.model.teste.InventarioTest.java

@Test
public void testarInventarioValido() throws CloneNotSupportedException {
    Inventario inventario = new Inventario(EMISSAO, mockGestor, listaBensSoUmItem);
    assertNull(inventario.getDataFechamento());
    Date dataFechamento = new Date();
    inventario.setDataFechamento(dataFechamento);
    assertEquals(EMISSAO, inventario.getDataEmissao());
    DateUtils.isSameDay(EMISSAO, inventario.getDataFechamento());
    assertTrue(inventario.getDataFechamento() != dataFechamento);
    assertEquals(mockGestor, inventario.getGestor());
    assertTrue(inventario.getAnalisados().contains(new Analise(b1, inventario, null)));
}