Example usage for java.util GregorianCalendar get

List of usage examples for java.util GregorianCalendar get

Introduction

In this page you can find the example usage for java.util GregorianCalendar get.

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

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

@Override
public List<Programme> getProgrammes(List<Channel> channels, int day) throws Exception {
    List<Programme> result = new LinkedList<Programme>();
    Map<String, Channel> channelMap = new HashMap<String, Channel>();
    for (Channel c : channels) {
        if (c.enabled && c.source.equals(getName()))
            channelMap.put(c.id, c);/*from w w w  .j av  a  2s .  c om*/
    }

    GregorianCalendar now = new GregorianCalendar();
    GregorianCalendar date = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
            now.get(Calendar.DAY_OF_MONTH));
    date.add(Calendar.DAY_OF_MONTH, day);

    // Note: this fetches all programmes up to and including the
    // requested date!
    URL url = programmeUrl(0, day);
    JSONObject json = fetchJSON(url);

    // First parse the library
    JSONArray library = json.getJSONArray("library");
    parseLibrary(library);

    // Then the schedules
    JSONArray schedules = json.getJSONArray("schedule");
    for (int i = 0; i < schedules.size(); i++) {
        JSONObject schedule = schedules.getJSONObject(i);

        // Skip programme if station not in channel list
        String station = schedule.getString("station");
        if (!channelMap.containsKey(station)) {
            if (!config.quiet)
                logger.trace("Skipping programmes for channel " + station);
            continue;
        }
        Programme prog = createProgramme(schedule, channelMap);
        if (!prog.startTime.before(date.getTime()))
            result.add(prog);
    }

    return result;
}

From source file:gov.nih.nci.cabig.caaers.domain.DateValue.java

/**
 * Instantiates a new date value.//from  w ww  .  ja  v  a 2  s .c o  m
 *
 * @param date the date
 */
public DateValue(Date date) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    this.day = gc.get(Calendar.DAY_OF_MONTH);
    this.month = gc.get(Calendar.MONTH) + 1;
    this.year = gc.get(Calendar.YEAR);
}

From source file:org.webcat.grader.graphs.StackedAreaChart.java

@Override
protected JFreeChart generateChart(WCChartTheme chartTheme) {
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, xAxisLabel(), yAxisLabel(), tableXYDataset(),
            orientation(), true, false, false);

    XYPlot plot = chart.getXYPlot();//from w  w w. j  a  v  a2s  . c om

    long diff = (long) tableXYDataset().getXValue(0, tableXYDataset().getItemCount() - 1)
            - (long) tableXYDataset().getXValue(0, 0);

    GregorianCalendar calDiff = new GregorianCalendar();
    calDiff.setTime(new NSTimestamp(diff));

    // Set the time axis
    PeriodAxis axis = new PeriodAxis(null); // ( "Date" );
    PeriodAxisLabelInfo labelinfo[] = new PeriodAxisLabelInfo[2];

    if (calDiff.get(Calendar.DAY_OF_YEAR) > 1) {
        axis.setTimeZone(TimeZone.getTimeZone(user().timeZoneName()));
        axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class);
        axis.setMajorTickTimePeriodClass(org.jfree.data.time.Week.class);

        labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);

        labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);
    } else {
        axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Hour.class);

        labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("ha"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);

        labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM-d"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);
    }

    axis.setLabelInfo(labelinfo);
    plot.setDomainAxis(axis);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    NumberTickUnit tickUnit = new NumberTickUnit(5);
    rangeAxis.setTickUnit(tickUnit);

    XYAreaRenderer2 renderer = (XYAreaRenderer2) plot.getRenderer();
    renderer.setOutline(true);
    renderer.setAutoPopulateSeriesOutlinePaint(true);

    plot.setDomainMinorGridlinesVisible(false);
    plot.setRangeMinorGridlinesVisible(false);

    if (markValue != null) {
        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairValue(markValue.doubleValue());
        plot.setDomainCrosshairPaint(Color.red);
        plot.setDomainCrosshairStroke(MARKER_STROKE);
    }

    chart.getLegend().setBorder(0, 0, 0, 0);

    return chart;
}

From source file:it.projectAdministration.ProjectAdministrationTest.java

@Test
@Ignore("refactor with wsClient")
public void delete_version_of_multimodule_project() {
    GregorianCalendar today = new GregorianCalendar();
    SonarScanner build = SonarScanner.create(projectDir("shared/xoo-multi-modules-sample"))
            .setProperty("sonar.dynamicAnalysis", "false")
            .setProperty("sonar.projectDate", (today.get(Calendar.YEAR) - 1) + "-01-01");
    orchestrator.executeBuild(build);//from  w  ww.  j  a  v  a  2s.c  o  m

    // The analysis must be run once again to have an history so that it is possible
    // to set/delete version on old snapshot
    build.setProperty("sonar.projectDate", today.get(Calendar.YEAR) + "-01-01");
    orchestrator.executeBuild(build);

    // There are 7 modules
    assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(1);

    runSelenese(orchestrator,
            "/projectAdministration/ProjectAdministrationTest/project-administration/multimodule-project-modify-version.html");

    assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(2);

    runSelenese(orchestrator,
            "/projectAdministration/ProjectAdministrationTest/project-administration/multimodule-project-delete-version.html");

    assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(1);
}

From source file:org.apache.eagle.jpm.mr.history.crawler.JHFCrawlerDriverImpl.java

private void advanceOneDay() throws Exception {
    //flushJobCount();
    GregorianCalendar cal = new GregorianCalendar(timeZone);
    cal.set(this.processDate.year, this.processDate.month, this.processDate.day, 0, 0, 0);
    cal.add(Calendar.DATE, 1);/*from  w w  w. jav a2 s .  c  o m*/
    this.processDate.year = cal.get(Calendar.YEAR);
    this.processDate.month = cal.get(Calendar.MONTH);
    this.processDate.day = cal.get(Calendar.DAY_OF_MONTH);

    try {
        clearProcessedJob(cal);
    } catch (Exception e) {
        LOG.error("failed to clear processed job ", e);
    }

}

From source file:ejava.projects.edmv.bl.DataGen.java

private VehicleRegistration createXMLRegistration(DMVVehicleRegistration reg, PersonsType people) {
    VehicleRegistration xmlReg = new VehicleRegistration();
    xmlReg.setVehicle(new VehicleType());
    xmlReg.getVehicle().setVehicleColorPrimaryCode(new VCOType());
    xmlReg.getVehicle().setVehicleID(new IDType());
    xmlReg.getVehicle().getVehicleID().setID(new TextType());
    xmlReg.getVehicle().setVehicleMakeCode(new VMAType());
    xmlReg.getVehicle().setVehicleModelCode(new VMOType());
    xmlReg.getVehicle().setVehicleModelYearDate(new GYear());
    xmlReg.getVehicle().getVehicleModelYearDate().setValue(dtf.newXMLGregorianCalendar());
    xmlReg.setVehicleLicensePlateID(new IDType());
    xmlReg.getVehicleLicensePlateID().setID(new TextType());
    xmlReg.setVehicleRegistrationDecal(new DecalType());
    xmlReg.getVehicleRegistrationDecal().setDecalMonthDate(new GMonth());
    xmlReg.getVehicleRegistrationDecal().getDecalMonthDate().setValue(dtf.newXMLGregorianCalendar());
    xmlReg.getVehicleRegistrationDecal().setDecalYearDate(new GYear());
    xmlReg.getVehicleRegistrationDecal().getDecalYearDate().setValue(dtf.newXMLGregorianCalendar());

    xmlReg.setId("vr" + ++id);
    xmlReg.setSourceIDText("" + reg.getId());

    xmlReg.getVehicle().getVehicleColorPrimaryCode().setValue(reg.getColor());
    xmlReg.getVehicle().getVehicleID().getID().setValue(reg.getVin());
    xmlReg.getVehicle().getVehicleMakeCode().setValue(reg.getMake());
    xmlReg.getVehicle().getVehicleModelCode().setValue(reg.getModel());
    xmlReg.getVehicle().getVehicleModelYearDate().getValue().setYear(Integer.parseInt(reg.getYear()));

    xmlReg.getVehicleLicensePlateID().getID().setValue(reg.getTagNo());
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(reg.getExpiration());//from   w ww .jav  a  2  s .  co  m
    xmlReg.getVehicleRegistrationDecal().getDecalMonthDate().getValue()
            .setMonth(cal.get(GregorianCalendar.MONTH) + 1);
    xmlReg.getVehicleRegistrationDecal().getDecalYearDate().getValue().setYear(cal.get(GregorianCalendar.YEAR));

    log.debug("vehicle has " + reg.getOwners().size() + " owners");
    for (DMVPerson o : reg.getOwners()) {
        for (Person p : people.getPerson()) {
            if (p.getSourceIDText().equals("" + o.getId())) {
                xmlReg.getVehicle().getPropertyOwnerPerson().add(new ReferenceType(p));
            }
        }
    }
    return xmlReg;
}

From source file:ru.apertum.qsystem.server.model.calendar.CalendarTableModel.java

/**
 *  ? ? /*  w  ww  .j  a v  a 2 s. c  om*/
 * @param year
 */
public void checkSaturday(int year) {
    QLog.l().logger().debug(" ? ?");
    final GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.YEAR, year);
    final int ye = year % 4 == 0 ? 366 : 365;
    for (int d = 1; d <= ye; d++) {
        gc.set(GregorianCalendar.DAY_OF_YEAR, d);
        if (gc.get(GregorianCalendar.DAY_OF_WEEK) == 7) {
            addDay(gc.getTime(), true);
        }
    }
    fireTableDataChanged();
}

From source file:ru.apertum.qsystem.server.model.calendar.CalendarTableModel.java

/**
 *  ? ??? //  w w w  . j av  a  2s.  com
 * @param year
 */
public void checkSunday(int year) {
    QLog.l().logger().debug(" ? ???");
    final GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.YEAR, year);
    final int ye = year % 4 == 0 ? 366 : 365;
    for (int d = 1; d <= ye; d++) {
        gc.set(GregorianCalendar.DAY_OF_YEAR, d);
        if (gc.get(GregorianCalendar.DAY_OF_WEEK) == 1) {
            addDay(gc.getTime(), true);
        }
    }
    fireTableDataChanged();
}

From source file:edu.jhuapl.openessence.web.util.Filters.java

private Date muckDate(Date date, int prepull, String resolution, int calWeekStartDay) {
    GregorianCalendar x = new GregorianCalendar();
    x.setTime(date);//  w ww .j ava2 s. c  om
    if (resolution != null && resolution.equals("weekly")) {
        x.add(Calendar.DATE, (-7 * prepull));
        // make sure week starts on week start day defined
        // in message.properties or datasource groovy file
        while (x.get(Calendar.DAY_OF_WEEK) != calWeekStartDay) {
            x.add(Calendar.DATE, -1);
        }
    } else if (resolution != null && resolution.equals("monthly")) {
        x.set(Calendar.DAY_OF_MONTH, 1);
    } else if (resolution != null && resolution.equals("daily")) {
        x.add(Calendar.DATE, -prepull);
    }
    return x.getTime();
}

From source file:org.getobjects.appserver.core.WOMessage.java

public static String httpFormatDate(final GregorianCalendar _cal) {
    /*/* w w w  .  ja  v a 2 s  .co m*/
     * Most likely some Java lib already provides this formatter ... It
     * basically always formats UTC in the English locale and therefore can be
     * hardcoded.
     *
     * Sample: Wed, 15 Nov 1995 04:58:08 GMT
     */
    if (_cal == null)
        return null;

    _cal.setTimeZone(gmt);

    final StringBuilder sb = new StringBuilder(32);
    sb.append(httpDayNames[_cal.get(Calendar.DAY_OF_WEEK) - 1]);
    sb.append(", ");
    int t = _cal.get(Calendar.DAY_OF_MONTH);
    sb.append(t < 10 ? "0" + t : t);
    sb.append(' ');
    sb.append(httpMonthNames[_cal.get(Calendar.MONTH)]);
    sb.append(' ');
    sb.append(_cal.get(Calendar.YEAR));
    sb.append(' ');
    t = _cal.get(Calendar.HOUR_OF_DAY /* 0..23 */);
    sb.append(t < 10 ? "0" + t : t);
    sb.append(':');
    t = _cal.get(Calendar.MINUTE);
    sb.append(t < 10 ? "0" + t : t);
    sb.append(':');
    t = _cal.get(Calendar.SECOND);
    sb.append(t < 10 ? "0" + t : t);
    sb.append(" GMT");

    return sb.toString();
}