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:org.skfiy.typhon.spi.role.FinalRoleListener.java

private void executeEverydayLoop(Player player) {
    Calendar lastResetCal = Calendar.getInstance();
    lastResetCal.setTimeInMillis(player.getNormal().getLastResetTime());

    Calendar curCal = Calendar.getInstance();

    if (!DateUtils.isSameDay(lastResetCal, curCal)) {
        for (Event<Player> event : everydayLoopEvents) {
            event.invoke(player);/*from w  w w . j  av  a  2s .c  om*/
        }
    }

    player.getNormal().setLastResetTime(System.currentTimeMillis());
}

From source file:org.squashtest.tm.service.statistics.campaign.CampaignProgressionStatistics.java

private boolean isSameDay(Date d1, Date d2) {
    if (d1 == null || d2 == null) {
        return false;
    } else {//  w w  w.  j  a va 2s  .com
        return DateUtils.isSameDay(d1, d2);
    }
}

From source file:org.tinymediamanager.UpgradeTasks.java

/**
 * performs some upgrade tasks from one version to another<br>
 * <b>make sure, this upgrade can run multiple times (= needed for nightlies!!!)
 * /*from w w w .  j  a v a2 s  .  com*/
 * @param oldVersion
 *          our current version
 */
public static void performUpgradeTasksAfterDatabaseLoading(String oldVersion) {
    MovieList movieList = MovieList.getInstance();
    TvShowList tvShowList = TvShowList.getInstance();

    String v = "" + oldVersion;

    if (StringUtils.isBlank(v)) {
        v = "2.6.9"; // set version for other updates
    }

    // ****************************************************
    // PLEASE MAKE THIS TO RUN MULTIPLE TIMES WITHOUT ERROR
    // NEEDED FOR NIGHTLY SNAPSHOTS ET ALL
    // SVN BUILD IS ALSO CONSIDERED AS LOWER !!!
    // ****************************************************

    // upgrade to v2.7
    if (StrgUtils.compareVersion(v, "2.7") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.7");
        // delete tmm.odb; objectdb.conf; log dir
        FileUtils.deleteQuietly(new File("tmm.odb"));
        FileUtils.deleteQuietly(new File("tmm.odb$"));
        FileUtils.deleteQuietly(new File("objectdb.conf"));
        FileUtils.deleteQuietly(new File("log"));
        Globals.settings.removeSubtitleFileType(".idx"); // aww, we never removed...

        // We do not migrate settings!
        // We cannot determine, if a user has unset a value, or the default changed!
        // So reSet some default values, but ONLY for release ONCE;
        // else every start of prerel/nightly would reset this over and over again
        if (ReleaseInfo.isReleaseBuild()) {
            MovieModuleManager.MOVIE_SETTINGS.setImageBanner(true);
            MovieModuleManager.MOVIE_SETTINGS.setImageLogo(true);
            MovieModuleManager.MOVIE_SETTINGS.setImageClearart(true);
            MovieModuleManager.MOVIE_SETTINGS.setImageDiscart(true);
            MovieModuleManager.MOVIE_SETTINGS.setImageThumb(true);
            MovieModuleManager.MOVIE_SETTINGS.setUseTrailerPreference(true);
            Globals.settings.writeDefaultSettings(); // activate default plugins
        }
    }

    // upgrade to v2.7.2
    if (StrgUtils.compareVersion(v, "2.7.2") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.7.2");
        // we forgot to update the actor thumbs in DB
        for (Movie movie : movieList.getMovies()) {
            boolean dirty = false;
            for (MovieActor actor : movie.getActors()) {
                if (StringUtils.isNotBlank(actor.getThumbPath())) {
                    if (actor.updateThumbRoot(movie.getPath())) {
                        // true when changed
                        dirty = true;
                    }
                }
            }
            if (dirty) {
                movie.saveToDb();
            }
        }
    }

    // upgrade to v2.7.3
    if (StrgUtils.compareVersion(v, "2.7.3") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.7.3");
        // get movie set artwork
        for (MovieSet movieSet : movieList.getMovieSetList()) {
            MovieSetArtworkHelper.updateArtwork(movieSet);
            movieSet.saveToDb();
        }

        // reset new indicator
        for (Movie movie : movieList.getMovies()) {
            movie.setNewlyAdded(false);
            movie.saveToDb();
        }
        for (TvShow tvShow : tvShowList.getTvShows()) {
            for (TvShowEpisode episode : tvShow.getEpisodes()) {
                episode.setNewlyAdded(false);
                episode.saveToDb();
            }
            tvShow.saveToDb();
        }
    }

    // upgrade to v2.8
    if (StrgUtils.compareVersion(v, "2.8") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.8");

        // upgrade certification settings
        // if MP NFO style is chosen, set the certification style to TECHNICAL
        if (MovieModuleManager.MOVIE_SETTINGS.getMovieConnector() == MovieConnectors.MP) {
            MovieModuleManager.MOVIE_SETTINGS.setMovieCertificationStyle(CertificationStyle.TECHNICAL);
        }

        // reevaluate movie stacking and offline stubs (without the need for UDS) and save
        for (Movie movie : movieList.getMovies()) {
            movie.reEvaluateStacking();
            boolean isOffline = false;
            for (MediaFile mf : movie.getMediaFiles(MediaFileType.VIDEO)) {
                if ("disc".equalsIgnoreCase(mf.getExtension())) {
                    isOffline = true;
                }
            }
            movie.setOffline(isOffline);
            movie.saveToDb();
        }
    }
    // upgrade to v2.8.2
    if (StrgUtils.compareVersion(v, "2.8.2") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.8.2");

        Date initialDate = new Date(0);

        for (Movie movie : movieList.getMovies()) {
            if (movie.getReleaseDate() != null && DateUtils.isSameDay(initialDate, movie.getReleaseDate())) {
                movie.setReleaseDate((Date) null);
                movie.saveToDb();
            }
        }

        for (TvShow tvShow : tvShowList.getTvShows()) {
            if (tvShow.getFirstAired() != null && DateUtils.isSameDay(initialDate, tvShow.getFirstAired())) {
                tvShow.setFirstAired((Date) null);
                tvShow.saveToDb();
            }
            for (TvShowEpisode episode : tvShow.getEpisodes()) {
                if (episode.getFirstAired() != null
                        && DateUtils.isSameDay(initialDate, episode.getFirstAired())) {
                    episode.setFirstAired((Date) null);
                    episode.saveToDb();
                }
            }
        }
    }

    // upgrade to v2.8.3
    if (StrgUtils.compareVersion(v, "2.8.3") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.8.3");

        // reset "container format" for MFs, so that MI tries them again on next UDS (ISOs and others)
        // (but only if we do not have some video information yet, like "width")
        for (Movie movie : movieList.getMovies()) {
            boolean changed = false;
            for (MediaFile mf : movie.getMediaFiles(MediaFileType.VIDEO)) {
                if (mf.getVideoResolution().isEmpty()) {
                    mf.setContainerFormat("");
                    changed = true;
                }
            }
            if (changed) {
                movie.saveToDb();
            }
        }
        for (TvShow tvShow : tvShowList.getTvShows()) {
            for (TvShowEpisode episode : tvShow.getEpisodes()) {
                boolean changed = false;
                for (MediaFile mf : episode.getMediaFiles(MediaFileType.VIDEO)) {
                    if (mf.getVideoResolution().isEmpty()) {
                        mf.setContainerFormat("");
                        changed = true;
                    }
                }
                if (episode.isDisc()) {
                    // correct episode path when extracted disc folder
                    Path discRoot = episode.getPathNIO().toAbsolutePath(); // folder
                    String folder = tvShow.getPathNIO().relativize(discRoot).toString()
                            .toUpperCase(Locale.ROOT); // relative
                    while (folder.contains("BDMV") || folder.contains("VIDEO_TS")) {
                        discRoot = discRoot.getParent();
                        folder = tvShow.getPathNIO().relativize(discRoot).toString().toUpperCase(Locale.ROOT); // reevaluate
                        episode.setPath(discRoot.toAbsolutePath().toString());
                        changed = true;
                    }
                }
                if (changed) {
                    episode.saveToDb();
                }
            }
        }
    }

    // upgrade to v2.9
    if (StrgUtils.compareVersion(v, "2.9") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.9");

        // Update actors to current structure; add entitiy root and cleanout actor path
        for (Movie movie : movieList.getMovies()) {
            boolean changed = false;
            for (MovieActor a : movie.getActors()) {
                if (a.getEntityRoot().isEmpty()) {
                    a.setEntityRoot(movie.getPathNIO().toString());
                    a.setThumbPath("");
                    changed = true;
                }
            }
            for (MovieProducer a : movie.getProducers()) {
                if (a.getEntityRoot().isEmpty()) {
                    a.setEntityRoot(movie.getPathNIO().toString());
                    a.setThumbPath("");
                    changed = true;
                }
            }

            // also clean out the sorttitle if a movie set is assigned (not needed any more)
            if (movie.getMovieSet() != null) {
                movie.setSortTitle("");
                changed = true;
            }

            // re-evaluate MediaSource; changed *.strm files to MediaSource.STREAM
            if (movie.getMediaSource() == MediaSource.UNKNOWN) {
                MediaFile source = movie.getMediaFiles(MediaFileType.VIDEO).get(0);
                MediaSource ms = MediaSource.parseMediaSource(source.getPath());
                if (movie.getMediaSource() != ms) {
                    movie.setMediaSource(ms);
                    changed = true;
                }
            }

            if (changed) {
                movie.saveToDb();
            }
        }
        for (TvShow tvShow : tvShowList.getTvShows()) {
            boolean changed = false;
            for (TvShowActor a : tvShow.getActors()) {
                if (a.getEntityRoot().isEmpty()) {
                    a.setEntityRoot(tvShow.getPathNIO().toString());
                    a.setThumbUrl(a.getThumb());
                    a.setThumbPath("");
                    a.setThumb("");
                    changed = true;
                }
            }
            for (TvShowEpisode episode : tvShow.getEpisodes()) {
                for (TvShowActor a : episode.getActors()) {
                    if (a.getEntityRoot().isEmpty()) {
                        a.setEntityRoot(episode.getPathNIO().toString());
                        a.setThumbUrl(a.getThumb());
                        a.setThumbPath("");
                        a.setThumb("");
                        changed = true;
                    }
                }
            }
            if (changed) {
                tvShow.saveToDb();
            }
        }
    }

    // upgrade to v2.9.1
    if (StrgUtils.compareVersion(v, "2.9.1") < 0) {
        LOGGER.info("Performing database upgrade tasks to version 2.9.1");

        if (MovieModuleManager.MOVIE_SETTINGS.getMovieConnector() == MovieConnectors.XBMC) {
            MovieModuleManager.MOVIE_SETTINGS.setMovieConnector(MovieConnectors.KODI);
            Settings.getInstance().saveSettings();
        }

        // fix swedish subs detected as sme
        for (Movie movie : movieList.getMovies()) {
            boolean changed = false;
            for (MediaFile mf : movie.getMediaFiles()) {
                for (MediaFileSubtitle sub : mf.getSubtitles()) {
                    if ("sme".equals(sub.getLanguage())) {
                        sub.setLanguage("swe");
                        changed = true;
                    }
                }
            }
            if (changed) {
                movie.saveToDb();
            }
        }
        for (TvShow show : tvShowList.getTvShows()) {
            boolean changed = false;
            for (TvShowEpisode episode : show.getEpisodes()) {
                for (MediaFile mf : episode.getMediaFiles()) {
                    for (MediaFileSubtitle sub : mf.getSubtitles()) {
                        if ("sme".equals(sub.getLanguage())) {
                            sub.setLanguage("swe");
                            changed = true;
                        }
                    }
                }
                if (changed) {
                    episode.saveToDb();
                }
            }
        }
    }
}

From source file:pgentity.quest.LoginDayLogger.java

@Override
protected void genLog(LoginDayRecord record) {
    RedisKey key = logPool.beginLog("login_day");

    Date lastLoginDate = new Date(getLastLogin(key));
    Date now = new Date(record.getLoginTime());

    if (!DateUtils.isSameDay(lastLoginDate, now)) {
        DBContext.Redis().hincrby(key, "login_day", 1);
    }/*from  w w w .  ja va  2  s.com*/

    DBContext.Redis().hset(key, "last_login", String.valueOf(record.getLoginTime()));

    logPool.endLog("login_day");
}

From source file:pgentity.services.restores.RestoreServices.java

public Map<String, Date> restoreIn(Date from, Date to) {
    PGException.Assert(from.before(to), PGError.UNDEFINED,
            "From day " + from + " must be lesser than to day " + to);
    Map<String, Pair<Date, File>> lastActive = new HashMap();
    for (Date day = from; day.before(to) || DateUtils.isSameDay(day, to); day = DateUtils.addDays(day, 1)) {
        List<File> files = getA1File(day);
        for (File file : files) {
            lastActive.put(FilenameUtils.removeExtension(file.getName()), Pair.of(day, file));
        }//w w w . ja  va  2s. co m
    }

    Map<String, Date> ret = new HashMap(lastActive.size());
    for (Map.Entry<String, Pair<Date, File>> restEntry : lastActive.entrySet()) {
        String uid = restEntry.getKey();
        File file = restEntry.getValue().getValue();

        try {
            restoreFromFile(uid, file);
            ret.put(uid, restEntry.getValue().getKey());
        } catch (IOException ex) {
            Logger.getLogger(RestoreServices.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return ret;
}

From source file:py.una.pol.karaku.test.test.FormatProviderTest.java

@Test
public void testShortDate() throws ParseException {

    assertEquals(SHORT_DATE, fp.asShortDate(date));
    assertTrue(DateUtils.isSameDay(date, fp.parseShortDate(SHORT_DATE)));

    assertEquals(EMPTY_STRING, fp.asShortDate((Date) null));
    assertEquals(null, fp.parseShortDate(EMPTY_STRING));
    assertEquals(null, fp.parseShortDate((String) null));
    assertEquals(SHORT_DATE, fp.asShortDate(fp.parseShortDate(SHORT_DATE)));

}

From source file:py.una.pol.karaku.test.test.FormatProviderTest.java

@Test
public void testLongDate() throws ParseException {

    assertEquals(LONG_DATE, fp.asDate(date));
    assertTrue(DateUtils.isSameDay(date, fp.parseDate(LONG_DATE)));

    assertEquals(EMPTY_STRING, fp.asDate(null));
    assertEquals(null, fp.parseDate(EMPTY_STRING));
    assertEquals(null, fp.parseDate(null));

    assertEquals(LONG_DATE, fp.asDate(fp.parseDate(LONG_DATE)));
}

From source file:py.una.pol.karaku.test.test.FormatProviderTest.java

private boolean hasSameHourMinuteAndDate(Date one, Date two) {

    return DateUtils.isSameDay(one, two) && this.hasSameHourAndMinute(one, two);
}

From source file:ren.hankai.cordwood.core.convert.StringToDateConverterTest.java

@Test
public void testConvertWithformat() throws Exception {
    final String format = "yyyy|MM|dd";
    final StringToDateConverter converter = new StringToDateConverter(format);

    final Date now = new Date();
    // 3?/* w  w  w  . ja v  a2 s  .c o m*/
    for (int i = 1; i <= testDays; i++) {
        final Date expDate = DateUtils.addDays(now, i);
        final String strDate = DateFormatUtils.format(expDate, format);
        final Date actual = converter.convert(strDate);
        Assert.assertTrue(DateUtils.isSameDay(actual, expDate));
    }
}

From source file:ren.hankai.cordwood.core.convert.StringToDateConverterTest.java

@Test
public void testConvertWithoutformat() throws Exception {
    final StringToDateConverter converter = new StringToDateConverter(null);

    final Date now = new Date();
    // 3?// w w  w.j a v a  2  s .  co m
    for (int i = 1; i <= testDays; i++) {
        final Date expDate = DateUtils.addDays(now, i);
        String strDate = null;
        if ((i % 2) == 0) {
            strDate = DateFormatUtils.format(expDate, "yyyy-MM-dd");
            final Date actual = converter.convert(strDate);
            Assert.assertTrue(DateUtils.isSameDay(actual, expDate));
        } else {
            strDate = DateFormatUtils.format(expDate, "yyyy-MM-dd HH:mm:ss");
            final Date actual = converter.convert(strDate);
            Assert.assertTrue(DateUtils.truncatedEquals(actual, expDate, Calendar.SECOND));
        }
    }
}