Example usage for java.util Calendar roll

List of usage examples for java.util Calendar roll

Introduction

In this page you can find the example usage for java.util Calendar roll.

Prototype

public void roll(int field, int amount) 

Source Link

Document

Adds the specified (signed) amount to the specified calendar field without changing larger fields.

Usage

From source file:au.com.jwatmuff.eventmanager.model.misc.SessionLockerTest.java

private static Session setupUnlockedSession(TransactionalDatabase database) throws IOException {
    Session session = null;/* w w  w .j av a  2 s.c  om*/
    try {
        CSVImporter.importPlayers(new File("test/player_test_data.csv"), database);
        CSVImporter.importPools(new File("test/pool_test_data.csv"), database);

        CompetitionInfo ci = new CompetitionInfo();
        Calendar cal = new GregorianCalendar(2008, 1, 1);
        ci.setStartDate(cal.getTime());
        cal.roll(GregorianCalendar.DATE, 2);
        ci.setEndDate(cal.getTime());
        ci.setAgeThresholdDate(cal.getTime());
        ci.setName("My Comp");
        ci.setMats(1);
        database.add(ci);

        // lock all players so they can be assigned to pools
        for (Player p : database.findAll(Player.class, PlayerDAO.ALL)) {
            p.setWeight(65.0);
            database.update(p);
            PlayerLocker.lockPlayer(database, p);
        }

        AutoAssign.assignPlayersToPools(database);

        Pool pool = database.findAll(Pool.class, PoolDAO.WITH_PLAYERS).iterator().next();
        for (PlayerPool pp : database.findAll(PlayerPool.class, PlayerPoolDAO.FOR_POOL, pool.getID())) {
            pp.setApproved(true);
            database.update(pp);
        }
        pool = PoolLocker.lockPoolPlayers(database, pool);
        FightGenerator.generateFightsForPool(database, pool);

        pool = PoolLocker.lockPoolFights(database, pool);

        Session mat = new Session();
        mat.setType(Session.SessionType.MAT);
        mat.setMat("Mat");
        database.add(mat);

        session = new Session();
        session.setType(Session.SessionType.NORMAL);
        session.setName("Session");

        Collection<Session> preceding = new ArrayList<Session>();
        Collection<Pool> pools = new ArrayList<Pool>();
        pools.add(pool);

        SessionLinker.insertSession(database, session, mat, preceding, pools);
    } catch (DatabaseStateException ex) {
        fail(ex.getMessage());
    }

    return session;
}

From source file:com.pureinfo.srm.project.ProjectToFinishRemindJob.java

private static Date getNMonthLater(int _n) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getDefault());
    cal.roll(Calendar.MONTH, _n);
    return cal.getTime();
}

From source file:com.project.framework.util.DateUtils.java

/**
 * ??(?)./*from www  .  j  a v  a  2  s.  c om*/
 * 
 * @param date ?
 * @return Date ??
 */
public static Date getBeforeTrad(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    do {
        calendar.roll(Calendar.DATE, false);
    } while (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7);

    return calendar.getTime();
}

From source file:com.project.framework.util.DateUtils.java

/**
 * ??(?)/* w w  w  .jav  a 2  s . c om*/
 * 
 * @param date ?
 * @return Date ??
 */
public static Date getAfterTrad(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    do {
        calendar.roll(Calendar.DATE, true);
    } while (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7);

    return calendar.getTime();
}

From source file:com.dianxin.imessage.common.util.DateUtil.java

/**
 * // w ww. j a  v  a 2  s .  c o m
 *
 * @return
 */
public static int calculateDays() {
    Calendar cd = Calendar.getInstance();
    cd.set(Calendar.DAY_OF_YEAR, 1);// 
    cd.roll(Calendar.DAY_OF_YEAR, -1);// 
    int MaxYear = cd.get(Calendar.DAY_OF_YEAR);
    return MaxYear;
}

From source file:com.kongwu.insweb.utils.DateUtils.java

/***
 * ?/*from  w  w  w.j  a v  a2  s  .com*/
 * @Title: getLastDayOfMonth
 * @param date
 * @throws
 */
public static Date getLastDayOfMonth(Date date) {
    Calendar cal = date2Calendar(date);
    cal.setTime(date);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.roll(Calendar.DAY_OF_MONTH, -1);
    return cal.getTime();
}

From source file:com.project.framework.util.DateUtils.java

/**
 * ??(?)//from   w  ww  . j  a v a 2s  .com
 * 
 * @param date ?
 * @return Date ??
 */
public static Date getMonthFirstTrad(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(getMonthFistDay(date));

    while (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7) {
        calendar.roll(Calendar.DATE, true);
    }

    return calendar.getTime();
}

From source file:com.project.framework.util.DateUtils.java

/**
 * ??(?)//w  w w.j  a  v a2s.c o m
 * 
 * @param date ?
 * @return Date ??
 */
public static Date getMonthLastTrad(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(getMonthLastDay(date));

    while (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7) {
        calendar.roll(Calendar.DATE, false);
    }

    return calendar.getTime();
}

From source file:de.knurt.fam.template.util.ContactDetailsRequestHandler.java

public static Date correctBirthdate(Date birthdate) {
    Calendar now = Calendar.getInstance();
    // older then 0?
    if (birthdate != null) {
        if (birthdate.after(now.getTime())) {
            birthdate = null;//from   w  w w. j av  a  2 s . c om
        }
    }
    if (birthdate != null) {
        // younger then 200?
        now.roll(Calendar.YEAR, -200);
        if (birthdate.before(now.getTime())) {
            birthdate = null;
        }
    }
    return birthdate;
}

From source file:fr.inria.ucn.Helpers.java

/**
 * @param c// w  w  w.  j  a  v a  2 s  . c  om
 * @return <code>True</code> if user has enabled the night-time mode and current time is
 * within night, else <code>False</code>.
 */
public static boolean isNightTime(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false))
        return false;

    int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600);
    int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600);

    Calendar nightstart = Calendar.getInstance();
    nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY));
    nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE));
    nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND));
    nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND));
    nightstart.add(Calendar.SECOND, nstart);

    Calendar nightstop = Calendar.getInstance();
    nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY));
    nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE));
    nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND));
    nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND));
    nightstop.add(Calendar.SECOND, nstop);
    if (nightstop.before(nightstart))
        nightstop.add(Calendar.HOUR, 24);

    Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString());
    Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString());

    Calendar now = Calendar.getInstance();
    return (now.after(nightstart) && now.before(nightstop));
}