Example usage for java.util Calendar add

List of usage examples for java.util Calendar add

Introduction

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

Prototype

public abstract void add(int field, int amount);

Source Link

Document

Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:org.geometerplus.android.fbreader.network.BearerAuthenticator.java

static boolean onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    final BearerAuthenticator ba = ourAuthenticators.get(activity);
    boolean processed = true;
    try {/*from w w  w .  j av  a  2s . c  om*/
        switch (requestCode) {
        default:
            processed = false;
            break;
        case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER:
            if (resultCode == Activity.RESULT_OK && data != null) {
                ba.myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            }
            break;
        case NetworkLibraryActivity.REQUEST_AUTHORISATION:
            if (resultCode == Activity.RESULT_OK) {
                ba.myAuthorizationConfirmed = true;
            }
            break;
        case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN:
            if (resultCode == Activity.RESULT_OK && data != null) {
                final CookieStore store = ZLNetworkManager.Instance().cookieStore();
                final Map<String, String> cookies = (Map<String, String>) data
                        .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY);
                if (cookies != null) {
                    for (Map.Entry<String, String> entry : cookies.entrySet()) {
                        final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue());
                        c.setDomain(data.getData().getHost());
                        c.setPath("/");
                        final Calendar expire = Calendar.getInstance();
                        expire.add(Calendar.YEAR, 1);
                        c.setExpiryDate(expire.getTime());
                        c.setSecure(true);
                        c.setDiscard(false);
                        store.addCookie(c);
                    }
                }
            }
            break;
        }
    } finally {
        if (processed) {
            synchronized (ba) {
                ba.notifyAll();
            }
        }
        return processed;
    }
}

From source file:com.cablevision.util.sso.UtilSSO.java

/**
 * Gets the date and time for the beginning of the Assertion time interval in
 * as specified by SAML v2.0 section 2.5.1.
 *
 * @return the date and time as a String
 *//*from  w w w  .ja va2  s.c  om*/
public static String getNotBeforeDateAndTime() {
    Calendar beforeCal = Calendar.getInstance();
    beforeCal.add(Calendar.MINUTE, ASSERTION_NOT_BEFORE_MINUTES);
    return DATE_TIME_FORMAT.format(beforeCal.getTime());
}

From source file:Main.java

/**
 * Takes a date value as used in CPLC Date fields (represented by 2 bytes)
 * /*from   w w  w  .j  av a  2  s.  c  o  m*/
 * @param paramByte1
 * @param paramByte2
 * @throws IllegalArgumentException
 * @return
 */
public static Date calculateCplcDate(byte[] dateBytes) throws IllegalArgumentException {
    if (dateBytes == null || dateBytes.length != 2) {
        throw new IllegalArgumentException("Error! CLCP Date values consist always of exactly 2 bytes");
    }
    // current time
    Calendar now = Calendar.getInstance();

    int year = now.get(Calendar.YEAR);
    int startYearOfCurrentDecade = year - (year % 10);

    int days = 100 * (dateBytes[0] & 0xF) + 10 * (0xF & dateBytes[1] >>> 4) + (dateBytes[1] & 0xF);

    if (days > 366) {
        throw new IllegalArgumentException("Invalid date (or are we parsing it wrong??)");
    }

    Calendar calculatedDate = Calendar.getInstance();
    calculatedDate.clear();
    calculatedDate.set(Calendar.YEAR, startYearOfCurrentDecade + (0xF & dateBytes[0] >>> 4));
    calculatedDate.set(Calendar.DAY_OF_YEAR, days);
    while (calculatedDate.after(now)) {
        calculatedDate.add(Calendar.YEAR, -10);
    }
    return calculatedDate.getTime();
}

From source file:Main.java

public static ArrayList<String> getCurrentWeek() {
    SimpleDateFormat format = new SimpleDateFormat("dd");
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    ArrayList<String> days = new ArrayList<String>();
    for (int i = 0; i < 7; i++) {
        days.add(format.format(calendar.getTime()));
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }/*w  ww  .  j  ava2  s. c om*/
    return days;
}

From source file:com.knowbout.epg.EPG.java

private static void test(Configuration config) throws IOException {
    HibernateUtil.openSession();// w ww. j a v a 2s  .  c  om
    Configuration provider = config.subset("provider");
    File destinationFolder = new File(provider.getString("destinationFolder"));
    Configuration files = config.subset("files");
    File schedules = new File(destinationFolder, files.getString("schedules"));
    //Test loading

    GZIPInputStream uis = new GZIPInputStream(new FileInputStream(schedules));
    ScheduleParser SkedParser = new ScheduleParser();
    SkedParser.parseSchedule(uis, config);

    try {
        EPGProviderService service = new EPGProviderService();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 20);
        //Test date now.
        ScheduledProgram sp = service.getScheduledProgramByNetworkCallSign("P-C", "NBC", new Date());
        System.err.println("IS SP NULL: " + (sp == null));
        if (sp != null) {
            System.err.println("\tSP: " + sp.getProgramTitle() + "  " + sp.getProgramId());
        }

        sp = service.getScheduledProgramByNetworkCallSign("SDTW-C", "NBC", new Date());
        System.err.println("SDTW- IS SP NULL: " + (sp == null));
        if (sp != null) {
            System.err.println("\tSP: " + sp.getProgramTitle() + "  " + sp.getProgramId());
        }

        //      System.err.println("SP is :"  +sp.getProgramTitle());
        //      try {
        //      List<ScheduledProgram> skedProgs = service.getScheduleForShow("P-DC", "Survivorman", new Date(), cal.getTime(), 1);
        //      for (ScheduledProgram prog: skedProgs) {
        //         System.err.println(" limit 1 SHOW: " + prog.getProgramId()+ " " + prog.getEpisodeTitle() + " starts at " + prog.getStartTime() + " " + prog.getNetwork().getStationCallSign());
        //      }
        ////      sp = service.getScheduledProgram("CA04542:DEFAULT", "41", new Date());
        ////      System.err.println("SP is :"  +sp.getProgramTitle());
        //      skedProgs = service.getScheduleForShow("P-DC", "Survivorman", new Date(), cal.getTime(), 0);
        //      for (ScheduledProgram prog: skedProgs) {
        //         System.err.println("NO LIMIT SHOW: " + prog.getProgramId()+ " " + prog.getEpisodeTitle() + "(" + prog.getScheduleId()+")"+ " starts at " + prog.getStartTime()+ " " + prog.getNetwork().getStationCallSign());
        //      }
        //      sp = service.getScheduledProgram("CA04542:DEFAULT", "7", new Date());
        //      System.err.println("SP is :"  +sp.getProgramTitle());
        //      ScheduledProgram next = service.getNextShowing("CA04542:DEFAULT", "EP6856270007");
        //      if (next != null) {
        //         System.err.println("Next - " + next.getEpisodeTitle() + " starts at " + next.getStartTime());
        //      } else {
        //         System.err.println("Unable to find next showing");
        //      }
        //      ScheduledProgram last = service.getLastShowing("CA04542:DEFAULT", "EP6856270007");
        //      if (last != null) {
        //         System.err.println("Last - " + last.getEpisodeTitle() + " starts at " + last.getStartTime());
        //      } else {
        //         System.err.println("Unable to find last showing");
        //      }
        //      
        //      
    } finally {
        HibernateUtil.closeSession();
    }
    if (true) {
        System.exit(-1);
    }
}

From source file:mobile.tiis.appv2.helpers.Utils.java

public static Date addDays(Date date, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//  ww  w. j  a  v  a2  s .c om
    cal.add(Calendar.DATE, days);
    return cal.getTime();
}

From source file:mobile.tiis.appv2.helpers.Utils.java

public static Date addMonths(Date date, int mmonths) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from  w  w w  . ja  va2 s. c  o  m*/
    cal.add(Calendar.MONTH, mmonths);
    return cal.getTime();
}

From source file:mobile.tiis.appv2.helpers.Utils.java

public static Date addYears(Date date, int years) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*w ww  .  j  a v  a  2s .co m*/
    cal.add(Calendar.YEAR, years);
    return cal.getTime();
}

From source file:com.ms.app.web.commons.tools.DateViewTools.java

public static String yesterday() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    return getFormat(SIMPLE_DATE_FORMAT_PATTERN).format(calendar.getTime());
}

From source file:com.ms.app.web.commons.tools.DateViewTools.java

public static String yesterdayFull() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    return getFormat(FULL_DATE_FORMAT_PATTERN).format(calendar.getTime());
}