Example usage for java.util Calendar clone

List of usage examples for java.util Calendar clone

Introduction

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

Prototype

@Override
public Object clone() 

Source Link

Document

Creates and returns a copy of this object.

Usage

From source file:org.globus.workspace.client_core.utils.ScheduleUtils.java

public static String getShutdownMessage(Schedule schedule, boolean aligned) {

    if (schedule == null) {
        return null; // *** EARLY RETURN ***
    }//from ww  w.j av a 2 s .c o  m

    final Calendar started = schedule.getActualInstantiationTime();

    final String name = "Shutdown time: ";
    final String prefix;
    if (aligned) {
        prefix = "    " + name;
    } else {
        prefix = name;
    }

    final String stopMsg;
    if (started != null) {
        final Calendar stopTime = (Calendar) started.clone();
        stopTime.add(Calendar.SECOND, schedule.getDurationSeconds());
        stopMsg = prefix + stopTime.getTime().toString();
    } else {
        stopMsg = prefix + NO_TIME;
    }

    return stopMsg;
}

From source file:com.liusoft.dlog4j.velocity.DLOG_VelocityTool.java

/**
 * /*  w ww . j  a  v  a 2  s . co  m*/
 * 
 * @param cal
 * @return
 */
private static int getMonthDateCount(Calendar cal) {
    Calendar cal2 = (Calendar) cal.clone();
    cal2.add(Calendar.MONTH, 1);
    cal2.set(Calendar.DAY_OF_MONTH, 1);
    cal2.add(Calendar.DAY_OF_MONTH, -1);
    return cal2.get(Calendar.DAY_OF_MONTH);
}

From source file:org.vanbest.xmltv.Horizon.java

public static URL programmeUrl(Channel channel, int day) throws Exception {
    StringBuilder s = new StringBuilder(listings_url);
    s.append("?byStationId=");
    s.append(channel.id);//  w w w .jav a 2s  . com
    s.append("&sort=startTime&range=1-100");
    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 0);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.SECOND, 0);
    startTime.set(Calendar.MILLISECOND, 0);
    startTime.add(Calendar.DAY_OF_MONTH, day);
    Calendar endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.DAY_OF_MONTH, 1);
    s.append("&byStartTime=");
    s.append(startTime.getTimeInMillis());
    s.append("~");
    s.append(endTime.getTimeInMillis());

    return new URL(s.toString());
}

From source file:freebase.api.FreebaseAPIMusic.java

public static void FetchingFromGoogleAPI() {

    int max_step = 1;
    int step = 0;

    int month_step = 1;
    Calendar last_date = Calendar.getInstance();
    last_date.set(Calendar.YEAR, 2016);
    last_date.set(Calendar.MONTH, 0);
    last_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar from_date = Calendar.getInstance();
    from_date.set(Calendar.YEAR, 2000);
    from_date.set(Calendar.MONTH, 0);
    from_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar to_date = (Calendar) from_date.clone();
    to_date.add(Calendar.MONTH, month_step);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    while (true) {
        //            if (step > max_step) {
        //                break;
        //            }
        //            System.out.println(">>> Cursor = " + current_cursor);
        //            if (/*films == null || films.isEmpty() ||*/step == max_step) {
        //                System.out.println("Films is null or zero size. Break.");
        //                break;
        //            }
        if (from_date.after(last_date)) {
            System.out.println("Date is after last date");
            break;
        }//from  ww  w .  j  a v  a2 s .  co m
        String fromDate = sdf.format(from_date.getTime());
        String toDate = sdf.format(to_date.getTime());
        System.out.println(step + " ) fetch films from " + fromDate + " to " + toDate);
        step++;
        List<Recording> recordings = getRecording(fromDate, toDate);
        System.out.println("Films#: " + recordings.size());
        writeToFiles(recordings);
        //            for (Film f : films) {
        //                System.out.println(f);
        //            }
        from_date.add(Calendar.MONTH, month_step);
        to_date.add(Calendar.MONTH, month_step);

    }
}

From source file:freebase.api.FreebaseAPI.java

public static void FetchingFromGoogleAPI() {

    int max_step = 1;
    int step = 0;

    int month_step = 1;
    Calendar last_date = Calendar.getInstance();
    last_date.set(Calendar.YEAR, 2016);
    last_date.set(Calendar.MONTH, 0);
    last_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar from_date = Calendar.getInstance();
    from_date.set(Calendar.YEAR, 2010);
    from_date.set(Calendar.MONTH, 0);
    from_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar to_date = (Calendar) from_date.clone();
    to_date.add(Calendar.MONTH, month_step);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    while (true) {
        //            if (step > max_step) {
        //                break;
        //            }
        //            System.out.println(">>> Cursor = " + current_cursor);
        //            if (/*films == null || films.isEmpty() ||*/step == max_step) {
        //                System.out.println("Films is null or zero size. Break.");
        //                break;
        //            }
        if (from_date.after(last_date)) {
            System.out.println("Date is after last date");
            break;
        }//from w  w  w .  j a  va2  s . c  o  m
        String fromDate = sdf.format(from_date.getTime());
        String toDate = sdf.format(to_date.getTime());
        System.out.println(step + " ) fetch films from " + fromDate + " to " + toDate);
        step++;
        List<Film> films = getFilms(fromDate, toDate);
        System.out.println("Films#: " + films.size());
        writeToFiles(films);
        //            for (Film f : films) {
        //                System.out.println(f);
        //            }
        from_date.add(Calendar.MONTH, month_step);
        to_date.add(Calendar.MONTH, month_step);

    }
}

From source file:br.msf.commons.util.AbstractDateUtils.java

protected static Collection<Calendar> getBrasilianHolidays(final int year) {
    Collection<Calendar> holidays = new ArrayList<>();

    // feriados fixos
    holidays.add(new GregorianCalendar(year, Calendar.JANUARY, 1)); // Confraternizacao Universal
    holidays.add(new GregorianCalendar(year, Calendar.APRIL, 21)); // Tiradentes
    holidays.add(new GregorianCalendar(year, Calendar.MAY, 1)); // Dia do Trabalho
    holidays.add(new GregorianCalendar(year, Calendar.OCTOBER, 12)); // Nossa Senhora Aparecida
    holidays.add(new GregorianCalendar(year, Calendar.NOVEMBER, 2)); // Finados
    holidays.add(new GregorianCalendar(year, Calendar.NOVEMBER, 15)); // Proclamacao da Republica
    holidays.add(new GregorianCalendar(year, Calendar.DECEMBER, 25)); // Natal

    // feriados calculados
    Calendar pascoa = getSundayOfEaster(year);
    Calendar carnaval = (Calendar) pascoa.clone();
    carnaval.add(Calendar.DAY_OF_MONTH, -47);
    Calendar corpusChristi = (Calendar) pascoa.clone();
    corpusChristi.add(Calendar.DAY_OF_MONTH, 60);

    holidays.add(carnaval); // Carnaval
    holidays.add(pascoa); // Pascoa
    holidays.add(corpusChristi); // Corpus Christi

    return holidays;
}

From source file:br.ojimarcius.commons.util.AbstractDateUtils.java

protected static Collection<Calendar> getBrasilianHolidays(final int year) {
    Collection<Calendar> holidays = new ArrayList<Calendar>();

    // feriados fixos
    holidays.add(new GregorianCalendar(year, Calendar.JANUARY, 1)); // Confraternizacao Universal
    holidays.add(new GregorianCalendar(year, Calendar.APRIL, 21)); // Tiradentes
    holidays.add(new GregorianCalendar(year, Calendar.MAY, 1)); // Dia do Trabalho
    holidays.add(new GregorianCalendar(year, Calendar.OCTOBER, 12)); // Nossa Senhora Aparecida
    holidays.add(new GregorianCalendar(year, Calendar.NOVEMBER, 2)); // Finados
    holidays.add(new GregorianCalendar(year, Calendar.NOVEMBER, 15)); // Proclamacao da Republica
    holidays.add(new GregorianCalendar(year, Calendar.DECEMBER, 25)); // Natal

    // feriados calculados
    Calendar pascoa = getSundayOfEaster(year);
    Calendar carnaval = (Calendar) pascoa.clone();
    carnaval.add(Calendar.DAY_OF_MONTH, -47);
    Calendar corpusChristi = (Calendar) pascoa.clone();
    corpusChristi.add(Calendar.DAY_OF_MONTH, 60);

    holidays.add(carnaval); // Carnaval
    holidays.add(pascoa); // Pascoa
    holidays.add(corpusChristi); // Corpus Christi

    return holidays;
}

From source file:mchs.neverforget.NeverForgetActivity.java

public static int daysBetween(Calendar day1, Calendar day2) {
    Calendar dayOne = (Calendar) day1.clone(), dayTwo = (Calendar) day2.clone();

    if (dayOne.get(Calendar.YEAR) == dayTwo.get(Calendar.YEAR)) {
        return Math.abs(dayOne.get(Calendar.DAY_OF_YEAR) - dayTwo.get(Calendar.DAY_OF_YEAR));
    } else {//from   w  w  w .  j av a 2 s .c  om
        if (dayTwo.get(Calendar.YEAR) > dayOne.get(Calendar.YEAR)) {
            //swap them
            Calendar temp = dayOne;
            dayOne = dayTwo;
            dayTwo = temp;
        }
        int extraDays = 0;

        int dayOneOriginalYearDays = dayOne.get(Calendar.DAY_OF_YEAR);

        while (dayOne.get(Calendar.YEAR) > dayTwo.get(Calendar.YEAR)) {
            dayOne.add(Calendar.YEAR, -1);
            // getActualMaximum() important for leap years
            extraDays += dayOne.getActualMaximum(Calendar.DAY_OF_YEAR);
        }

        return extraDays - dayTwo.get(Calendar.DAY_OF_YEAR) + dayOneOriginalYearDays;
    }
}

From source file:com.alcatel_lucent.nz.wnmsextract.reader.FileUtilities.java

/**
 * Deletes any files downloaded from the previous day
 * @param cal. The day being processed NOT the day being deleted
 *///from  w w w  .  j a v a2  s .c o m
public static boolean deletePreviousDay(Calendar today, String temppath) {
    Calendar yesterday = (Calendar) today.clone();
    yesterday.add(Calendar.DATE, -2);
    File to_delete = new File(temppath + calendarToString(yesterday));
    return to_delete.delete();

}

From source file:freebase.api.FreebaseAPI2.java

public static void FetchingFromGoogleAPI() {

    int max_step = 1;
    int step = 0;

    int month_step = 1;
    Calendar last_date = Calendar.getInstance();
    last_date.set(Calendar.YEAR, 2016);
    last_date.set(Calendar.MONTH, 0);
    last_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar from_date = Calendar.getInstance();
    from_date.set(Calendar.YEAR, 2000);
    from_date.set(Calendar.MONTH, 0);
    from_date.set(Calendar.DAY_OF_MONTH, 1);

    Calendar to_date = (Calendar) from_date.clone();
    to_date.add(Calendar.MONTH, month_step);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    while (true) {
        //            if (step > max_step) {
        //                break;
        //            }
        //            System.out.println(">>> Cursor = " + current_cursor);
        //            if (/*films == null || films.isEmpty() ||*/step == max_step) {
        //                System.out.println("Films is null or zero size. Break.");
        //                break;
        //            }
        if (from_date.after(last_date)) {
            System.out.println("Date is after last date");
            break;
        }/*  www .  ja v  a2 s .c o  m*/
        String fromDate = sdf.format(from_date.getTime());
        String toDate = sdf.format(to_date.getTime());
        System.out.println(step + " ) fetch films from " + fromDate + " to " + toDate);
        step++;
        List<Film> films = getFilms(fromDate, toDate);
        System.out.println("Films#: " + films.size());
        writeToFiles(films);
        //            for (Film f : films) {
        //                System.out.println(f);
        //            }
        from_date.add(Calendar.MONTH, month_step);
        to_date.add(Calendar.MONTH, month_step);

    }
}