Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

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

Prototype

public final void clear() 

Source Link

Document

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:uk.me.g4dpz.satellite.PassPredictor.java

public Long getUplinkFreq(final Long freq, final Date date) throws InvalidTleException, SatNotFoundException {
    validateData();//  www .  j  a  v  a2s .c  om
    final Calendar cal = Calendar.getInstance(TZ);
    cal.clear();
    cal.setTimeInMillis(date.getTime());
    final SatPos satPos = getSatPos(cal.getTime());
    final double rangeRate = satPos.getRangeRate();
    return (long) ((double) freq * (SPEED_OF_LIGHT + rangeRate * 1000.0) / SPEED_OF_LIGHT);
}

From source file:uk.me.g4dpz.satellite.PassPredictor.java

/**
 * Gets the downlink frequency corrected for doppler.
 *
 * @param freq the original frequency in Hz
 * @return the doppler corrected frequency in Hz
 * @throws InvalidTleException bad TLE passed in
 * @throws SatNotFoundException/*from  www  . ja va 2 s  . co  m*/
 */
public Long getDownlinkFreq(final Long freq, final Date date) throws InvalidTleException, SatNotFoundException {
    validateData();
    // get the current position
    final Calendar cal = Calendar.getInstance(TZ);
    cal.clear();
    cal.setTimeInMillis(date.getTime());
    final SatPos satPos = getSatPos(cal.getTime());
    final double rangeRate = satPos.getRangeRate();
    return (long) ((double) freq * (SPEED_OF_LIGHT - rangeRate * 1000.0) / SPEED_OF_LIGHT);
}

From source file:com.discovery.darchrow.date.DateUtil.java

/**
 *  <code>week</code>./* w  ww .  j  a va 2  s .  c om*/
 * 
 * <pre>
 *   2015-7-29 14:08
 * 
 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY)
 * return 2015-01-02 00:00:00.000
 * 
 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY)
 * return 2015-01-05 00:00:00.000
 * </pre>
 * 
 * @param date
 *            
 * @param week
 *             1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY},
 *            {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY}
 * @return the first week of specify date year
 * @see Calendar#SUNDAY
 * @see Calendar#MONDAY
 * @see Calendar#TUESDAY
 * @see Calendar#WEDNESDAY
 * @see Calendar#THURSDAY
 * @see Calendar#FRIDAY
 * @see Calendar#SATURDAY
 * @since 1.3.0
 */
public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) {
    Calendar calendar = toCalendar(date);
    calendar.clear();
    calendar.set(Calendar.YEAR, getYear(date));
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
    calendar.set(Calendar.DAY_OF_WEEK, week);

    //DAY_OF_WEEK_IN_MONTH ? DAY_OF_WEEK ???
    // WEEK_OF_MONTH  WEEK_OF_YEAR ??? ? getFirstDayOfWeek()  getMinimalDaysInFirstWeek()

    //DAY_OF_MONTH 1  7  DAY_OF_WEEK_IN_MONTH 1
    //8  14  DAY_OF_WEEK_IN_MONTH 2?
    //DAY_OF_WEEK_IN_MONTH 0  DAY_OF_WEEK_IN_MONTH 1 ?
    //?? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1
    //?????
    // 31  DAY_OF_WEEK_IN_MONTH -1  DAY_OF_WEEK_IN_MONTH 5  DAY_OF_WEEK_IN_MONTH 4 ??
    return CalendarUtil.toDate(calendar);
}

From source file:org.ovirt.api.metamodel.tests.XmlWriterTest.java

/**
 * Checks that dates are written correctly.
 *///from  w  ww .j a  v  a  2s . co  m
@Test
public void testDate() {
    java.util.TimeZone tz = java.util.TimeZone.getTimeZone("UTC+1");
    Calendar calendar = Calendar.getInstance(tz);
    calendar.clear();
    calendar.set(2015, 12, 17, 16, 18, 23);
    calendar.set(Calendar.MILLISECOND, 123);
    Date date = calendar.getTime();
    V4Vm object = vm().creationTime(date).build();
    assertEquals("<vm><creation_time>2016-01-17T16:18:23.123Z</creation_time></vm>", objectToXml(object));
}

From source file:com.sentaca.spring.smpp.jsmpp.JSMPPGateway.java

private String formatTimeFromHours(int timeInHours) {
    if (timeInHours < 0) {
        return null;
    }//from   w  w w  . j a  v  a2 s .c o m
    Calendar cDate = Calendar.getInstance();
    cDate.clear();
    cDate.set(Calendar.YEAR, 0);
    cDate.add(Calendar.HOUR, timeInHours);

    int years = cDate.get(Calendar.YEAR) - cDate.getMinimum(Calendar.YEAR);
    int months = cDate.get(Calendar.MONTH);
    int days = cDate.get(Calendar.DAY_OF_MONTH) - 1;
    int hours = cDate.get(Calendar.HOUR_OF_DAY);

    String yearsString = (years < 10) ? "0" + years : years + "";
    String monthsString = (months < 10) ? "0" + months : months + "";
    String daysString = (days < 10) ? "0" + days : days + "";
    String hoursString = (hours < 10) ? "0" + hours : hours + "";

    return yearsString + monthsString + daysString + hoursString + "0000000R";
}

From source file:javasnack.h2.DbUnitCsvUsageTest.java

@BeforeTest
public void prepareDb() throws Exception {
    tmpDir = FileDirHelper.createTmpDir();

    Class.forName("org.h2.Driver");
    conn = DriverManager.getConnection("jdbc:h2:mem:test2", "sa", "");

    new T1().setup(conn);
    Calendar c = Calendar.getInstance();

    c.clear();
    c.set(2000, 11, 31, 23, 59, 59);//from ww w.  j  a  va  2s  .co  m
    long insertTIM = c.getTimeInMillis();
    new T1(true, 10, new BigDecimal(20), 30.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \"World\"!").insertMe(conn);

    c.clear();
    c.set(2001, 0, 1, 12, 30, 15);
    insertTIM = c.getTimeInMillis();
    new T1(false, 20, new BigDecimal(30), 40.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \n\"World\"!").insertMe(conn);

    new T2().setup(conn);
    new T2(10, "abc").insertMe(conn);
    new T2(20, "def").insertMe(conn);

    new T3().setup(conn);
    new T3("label100").insertMe(conn);
    new T3("label200").insertMe(conn);

    new T4().setup(conn);
    new T4(UnsignedByte.create0x00to0xFFString(), UnsignedByte.create0x00to0xFF(),
            UnsignedByte.create0x00to0xFF()).insertMe(conn);
}

From source file:org.spring.data.gemfire.rest.GemFireRestInterfaceTest.java

protected Date createDate(final int year, final int month, final int dayOfMonth) {
    Calendar dateTime = Calendar.getInstance();
    dateTime.clear();
    dateTime.set(Calendar.YEAR, year);
    dateTime.set(Calendar.MONTH, month);
    dateTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    return dateTime.getTime();
}

From source file:com.android.ddmuilib.log.event.DisplaySyncHistogram.java

/**
 * Creates a multiple-hour time period for the histogram.
 * @param time Time in milliseconds./*from w  w w .  ja v  a  2 s  . c  om*/
 * @param numHoursWide: should divide into a day.
 * @return SimpleTimePeriod covering the number of hours and containing time.
 */
private SimpleTimePeriod getTimePeriod(long time, long numHoursWide) {
    Date date = new Date(time);
    TimeZone zone = RegularTimePeriod.DEFAULT_TIME_ZONE;
    Calendar calendar = Calendar.getInstance(zone);
    calendar.setTime(date);
    long hoursOfYear = calendar.get(Calendar.HOUR_OF_DAY) + calendar.get(Calendar.DAY_OF_YEAR) * 24;
    int year = calendar.get(Calendar.YEAR);
    hoursOfYear = (hoursOfYear / numHoursWide) * numHoursWide;
    calendar.clear();
    calendar.set(year, 0, 1, 0, 0); // Jan 1
    long start = calendar.getTimeInMillis() + hoursOfYear * 3600 * 1000;
    return new SimpleTimePeriod(start, start + numHoursWide * 3600 * 1000);
}

From source file:org.apache.cocoon.generation.CalendarGenerator.java

/**
 * Generate XML data.//from w  w  w . j av a  2  s  .co m
 *
 * @throws  SAXException if an error occurs while outputting the document
 */
public void generate() throws SAXException, ProcessingException {
    Calendar start = Calendar.getInstance(locale);
    start.clear();
    start.set(Calendar.YEAR, this.year);
    start.set(Calendar.MONTH, this.month);
    start.set(Calendar.DAY_OF_MONTH, 1);
    Calendar end = (Calendar) start.clone();
    end.add(Calendar.MONTH, 1);

    // Determine previous and next months
    Calendar prevMonth = (Calendar) start.clone();
    prevMonth.add(Calendar.MONTH, -1);

    this.contentHandler.startDocument();
    this.contentHandler.startPrefixMapping(PREFIX, URI);
    attributes.clear();
    attributes.addAttribute("", YEAR_ATTR_NAME, YEAR_ATTR_NAME, "CDATA", String.valueOf(year));
    attributes.addAttribute("", MONTH_ATTR_NAME, MONTH_ATTR_NAME, "CDATA",
            monthFormatter.format(start.getTime()));

    // Add previous and next month
    attributes.addAttribute("", PREV_YEAR_ATTR_NAME, PREV_YEAR_ATTR_NAME, "CDATA",
            String.valueOf(prevMonth.get(Calendar.YEAR)));
    attributes.addAttribute("", PREV_MONTH_ATTR_NAME, PREV_MONTH_ATTR_NAME, "CDATA",
            monthNumberFormatter.format(prevMonth.get(Calendar.MONTH) + 1));
    attributes.addAttribute("", NEXT_YEAR_ATTR_NAME, NEXT_YEAR_ATTR_NAME, "CDATA",
            String.valueOf(end.get(Calendar.YEAR)));
    attributes.addAttribute("", NEXT_MONTH_ATTR_NAME, NEXT_MONTH_ATTR_NAME, "CDATA",
            monthNumberFormatter.format(end.get(Calendar.MONTH) + 1));

    this.contentHandler.startElement(URI, CALENDAR_NODE_NAME, PREFIX + ':' + CALENDAR_NODE_NAME, attributes);
    int weekNo = start.get(Calendar.WEEK_OF_MONTH);
    int firstDay = start.getFirstDayOfWeek();
    if (start.get(Calendar.DAY_OF_WEEK) != firstDay) {
        attributes.clear();
        attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA", String.valueOf(weekNo));
        this.contentHandler.startElement(URI, WEEK_NODE_NAME, PREFIX + ':' + WEEK_NODE_NAME, attributes);
        if (padWeeks) {
            Calendar previous = (Calendar) start.clone();
            while (previous.get(Calendar.DAY_OF_WEEK) != firstDay) {
                previous.add(Calendar.DAY_OF_MONTH, -1);
            }
            while (previous.before(start)) {
                attributes.clear();
                attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA",
                        String.valueOf(previous.get(Calendar.DAY_OF_MONTH)));
                attributes.addAttribute("", WEEKDAY_ATTR_NAME, WEEKDAY_ATTR_NAME, "CDATA",
                        weekdays[previous.get(Calendar.DAY_OF_WEEK)]);
                attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, "CDATA",
                        dateFormatter.format(previous.getTime()));
                this.contentHandler.startElement(URI, DAY_NODE_NAME, PREFIX + ':' + DAY_NODE_NAME, attributes);
                addContent(previous, locale);
                this.contentHandler.endElement(URI, DAY_NODE_NAME, PREFIX + ':' + DAY_NODE_NAME);
                previous.add(Calendar.DAY_OF_MONTH, 1);
            }
        }
    }
    while (start.before(end)) {
        if (start.get(Calendar.DAY_OF_WEEK) == firstDay) {
            weekNo = start.get(Calendar.WEEK_OF_MONTH);
            attributes.clear();
            attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA", String.valueOf(weekNo));
            this.contentHandler.startElement(URI, WEEK_NODE_NAME, PREFIX + ':' + WEEK_NODE_NAME, attributes);
        }
        attributes.clear();
        attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA",
                String.valueOf(start.get(Calendar.DAY_OF_MONTH)));
        attributes.addAttribute("", WEEKDAY_ATTR_NAME, WEEKDAY_ATTR_NAME, "CDATA",
                weekdays[start.get(Calendar.DAY_OF_WEEK)]);
        attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, "CDATA",
                dateFormatter.format(start.getTime()));
        this.contentHandler.startElement(URI, DAY_NODE_NAME, PREFIX + ':' + DAY_NODE_NAME, attributes);
        addContent(start, locale);
        this.contentHandler.endElement(URI, DAY_NODE_NAME, PREFIX + ':' + DAY_NODE_NAME);
        start.add(Calendar.DAY_OF_MONTH, 1);
        if (start.get(Calendar.DAY_OF_WEEK) == firstDay || (!padWeeks && !start.before(end))) {
            this.contentHandler.endElement(URI, WEEK_NODE_NAME, PREFIX + ':' + WEEK_NODE_NAME);
        }
    }

    if (padWeeks) {
        while (firstDay != end.get(Calendar.DAY_OF_WEEK)) {
            attributes.clear();
            attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA",
                    String.valueOf(end.get(Calendar.DAY_OF_MONTH)));
            attributes.addAttribute("", WEEKDAY_ATTR_NAME, WEEKDAY_ATTR_NAME, "CDATA",
                    weekdays[end.get(Calendar.DAY_OF_WEEK)]);
            attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, "CDATA",
                    dateFormatter.format(end.getTime()));
            this.contentHandler.startElement(URI, DAY_NODE_NAME, PREFIX + ':' + DAY_NODE_NAME, attributes);
            addContent(end, locale);
            this.contentHandler.endElement(URI, DAY_NODE_NAME, PREFIX + ':' + DAY_NODE_NAME);
            end.add(Calendar.DAY_OF_MONTH, 1);
            if (firstDay == end.get(Calendar.DAY_OF_WEEK)) {
                this.contentHandler.endElement(URI, WEEK_NODE_NAME, PREFIX + ':' + WEEK_NODE_NAME);
            }
        }
    }
    this.contentHandler.endElement(URI, CALENDAR_NODE_NAME, PREFIX + ':' + CALENDAR_NODE_NAME);
    this.contentHandler.endPrefixMapping(PREFIX);
    this.contentHandler.endDocument();
}

From source file:org.polymap.biotop.ui.BiotopFilterProvider.java

protected Date[] yearFromTo(String year) {
    Date[] result = new Date[2];
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.YEAR, Integer.parseInt(year));
    result[0] = cal.getTime();/*from   w ww.  ja va 2 s. c om*/
    cal.add(Calendar.YEAR, 1);
    result[1] = cal.getTime();
    return result;
}