Example usage for java.util Date setMonth

List of usage examples for java.util Date setMonth

Introduction

In this page you can find the example usage for java.util Date setMonth.

Prototype

@Deprecated
public void setMonth(int month) 

Source Link

Document

Sets the month of this date to the specified value.

Usage

From source file:ezbake.services.provenance.graph.Utils.java

public static ezbake.base.thrift.DateTime convertDate2DateTime(final java.util.Date theDate) {
    final Calendar cal = new GregorianCalendar();
    cal.setTime(theDate);/*from  ww  w  .  j a  v  a2s  .c  o m*/

    // get calendar parts
    final int year = cal.get(Calendar.YEAR);
    final int month = cal.get(Calendar.MONTH) + 1;
    final int day = cal.get(Calendar.DAY_OF_MONTH);
    final int hour = cal.get(Calendar.HOUR_OF_DAY);
    final int minute = cal.get(Calendar.MINUTE);
    final int second = cal.get(Calendar.SECOND);
    int offsetMinutes = (cal.getTimeZone().getOffset(cal.getTimeInMillis())) / (1000 * 60);

    // set thrift DateTime propertiesd
    final ezbake.base.thrift.DateTime dt = new ezbake.base.thrift.DateTime();
    // Date
    final ezbake.base.thrift.Date date = new ezbake.base.thrift.Date();
    date.setMonth((short) month).setDay((short) day).setYear((short) year);
    dt.setDate(date);

    // Time with TimeZone
    final ezbake.base.thrift.Time t = new ezbake.base.thrift.Time();
    boolean afterUtc = offsetMinutes > 0;
    offsetMinutes = Math.abs(offsetMinutes);
    final ezbake.base.thrift.TimeZone tz = new ezbake.base.thrift.TimeZone((short) (offsetMinutes / 60),
            (short) (offsetMinutes % 60), afterUtc);
    t.setHour((short) hour).setMinute((short) minute).setSecond((short) second).setTz(tz);
    dt.setTime(t);

    return dt;
}

From source file:ucd.denver.com.diskussioner.entityParser.parseToJson.java

public static List<Discussion> parseToDiscussion(String content) {
    try {/*from   ww  w  .j a  v a 2 s  . c o m*/
        JSONArray ja = new JSONArray(content);
        List<Discussion> disList = new ArrayList<>();
        for (int i = 0; i < ja.length(); i++) {
            JSONObject jo = ja.getJSONObject(i);
            Discussion d = new Discussion();
            d.setId(jo.getInt("id"));
            String da = jo.getString("started_date").toString();
            System.out.println(da);
            Date statedDate = new Date();
            String[] dateSplit = da.split("-");
            statedDate.setYear(Integer.parseInt(dateSplit[0]) - 1900);
            statedDate.setMonth(Integer.parseInt(dateSplit[1]));
            statedDate.setDate(Integer.parseInt(dateSplit[2]));

            System.out.println(statedDate);
            System.out.println("stated Date" + statedDate);
            d.setStartedDate(statedDate);
            d.setTopic(jo.getString("topic"));
            User u = new User();
            u.setEmail(jo.getString("started_user"));
            d.setStartedUser(u);
            disList.add(d);

        }
        System.out.println("dis List size:::" + disList.size());
        return disList;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}

From source file:com.autentia.tnt.bean.billing.BillExpirationDateBean.java

public void updateExpirationDate() {

    // TODO extract login name to a properties file
    authenticateAs(ConfigurationUtil.getDefault().getAdminUser());

    List<Bill> bills = BillManager.getDefault().getAllEntities(null, new SortCriteria("name"));

    for (Bill b : bills) {

        Date creationDate = b.getCreationDate();

        creationDate.setMonth(creationDate.getMonth() + 1);
        if (!b.getBillPayment().isEmpty()) {
            for (BillPayment bp : b.getBillPayment()) {

                bp.setExpirationDate(creationDate);
            }//from   w w w  . j ava2s.c o m
        } else {
            //creamos el billPayment para el expirationDate
            createBillPayment(b);
            for (BillPayment bp : b.getBillPayment()) {
                bp.setExpirationDate(creationDate);
            }

        }
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFNextDay.java

public String evaluate(String date, Integer day) {
    if (date == null || day == null) {
        return null;
    }/*from  ww  w . j a va 2  s .co m*/

    if (day < 1 || day > 7) {
        return null;
    }

    Pattern pattern = Pattern.compile("([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])[\\s\\S]*(\\..*)?$");

    Matcher matcher = pattern.matcher(date);

    if (!matcher.matches()) {
        return null;
    }

    int year = Integer.valueOf(matcher.group(1));
    int month = Integer.valueOf(matcher.group(2));
    int dd = Integer.valueOf(matcher.group(3));

    Date ret = new Date();
    ret.setYear(year - 1900);
    ret.setMonth(month - 1);
    ret.setDate(dd);

    ret.setHours(0);
    ret.setMinutes(0);
    ret.setSeconds(0);

    Calendar curr = Calendar.getInstance();
    curr.setTime(ret);

    int curr_week = curr.get(Calendar.DAY_OF_WEEK);
    int offset = 7 + (day - curr_week);

    curr.add(Calendar.DAY_OF_WEEK, offset);

    Date newDate = curr.getTime();
    System.out.println("newDate:" + newDate.toString());

    year = curr.get(Calendar.YEAR);
    month = curr.get(Calendar.MONTH) + 1;
    dd = curr.get(Calendar.DAY_OF_MONTH);

    System.out.println("curr.get(Calendar.MONTH):" + curr.get(Calendar.MONTH));

    return String.format("%04d-%02d-%02d", year, month, dd);
}

From source file:org.apache.lens.cube.metadata.TimePartition.java

private Date truncate(Date date, UpdatePeriod updatePeriod) {
    if (updatePeriod.equals(UpdatePeriod.WEEKLY)) {
        Date truncDate = DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
        Calendar cal = Calendar.getInstance();
        cal.setTime(truncDate);//www .  j a  v a2  s  . co m
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
        return cal.getTime();
    } else if (updatePeriod.equals(UpdatePeriod.QUARTERLY)) {
        Date dt = DateUtils.truncate(date, updatePeriod.calendarField());
        dt.setMonth(dt.getMonth() - dt.getMonth() % 3);
        return dt;
    } else {
        return DateUtils.truncate(date, updatePeriod.calendarField());
    }
}

From source file:org.openmrs.module.vcttrac.web.view.chart.EvolutionOfClientRegisteredPerDay.java

/**
 * @see org.openmrs.module.vcttrac.web.view.chart.AbstractChartView#createChart(java.util.Map,
 *      javax.servlet.http.HttpServletRequest)
 *//*from   w  w  w. ja  v a2 s.c o  m*/
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {

    String categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.yAxis.days", null);
    String valueAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.xAxis.numberofclient", null);

    int numberOfDays = 7, dayFormat = 1;

    if (request.getParameter("graphCategory") != null) {
        if (request.getParameter("graphCategory").trim().compareTo("2") == 0) {
            Date d = new Date();
            d.setDate(1);
            d.setMonth((new Date()).getMonth());
            d.setYear((new Date()).getYear());

            numberOfDays = (int) (((new Date()).getTime() - d.getTime())
                    / VCTTracConstant.ONE_DAY_IN_MILLISECONDS);

            categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.month." + ((new Date()).getMonth() + 1), null);
            dayFormat = 2;

        }
    }

    String title = "";
    title = VCTTracUtil.getMessage("vcttrac.graph.evolution.client.received", null);

    JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel,
            createDataset(numberOfDays, dayFormat), // data
            PlotOrientation.VERTICAL, true, false, false);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...   
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setUpperMargin(0.15);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // customise the renderer...   
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelsVisible(true);

    return chart;
}

From source file:v2.ClientTest.java

@Test
public void testDatesLaptop() throws APIException {
    Laptop laptop = new Laptop();
    laptop.setStatus(Laptop.TAGGED_S0);/*from   w  ww .  j  a  v a  2s .  c  om*/
    Date dateDelivered = new Date();
    dateDelivered.setHours(12);
    dateDelivered.setMinutes(45);
    dateDelivered.setSeconds(10);

    dateDelivered.setMonth(3);
    dateDelivered.setYear(2012);

    laptop.setDateDelivered(dateDelivered);
    Date dateReceived = new Date();
    dateReceived.setHours(1);
    dateReceived.setMinutes(41);
    dateReceived.setSeconds(10);
    dateReceived.setMonth(5);
    dateReceived.setYear(2012);
    laptop.setDateReceived(dateReceived);

    Date dateRecycled = new Date();
    dateRecycled.setHours(1);
    dateRecycled.setMinutes(35);
    dateRecycled.setSeconds(10);
    dateRecycled.setMonth(4);
    dateRecycled.setYear(2012);
    laptop.setDateRecycled(dateRecycled);
    String nid = client.addLaptop(laptop);

    // Check date laptop

    // Laptop laptop = client.getLaptop(nid);
    // log.info(laptop);
    // log.info("Response test: "+nid);
    boolean result = client.deleteLaptop(nid);
    // log.info("It was deleted: "+result);
    Assert.assertTrue(result);

}

From source file:org.epics.archiverappliance.etl.ConsolidateETLJobsForOnePVTest.java

@SuppressWarnings("deprecation")
private void Consolidate() throws AlreadyRegisteredException, IOException, InterruptedException {
    PVTypeInfo typeInfo = new PVTypeInfo(pvName, ArchDBRTypes.DBR_SCALAR_DOUBLE, true, 1);
    String[] dataStores = new String[] { storageplugin1.getURLRepresentation(),
            storageplugin2.getURLRepresentation(), storageplugin3.getURLRepresentation() };
    typeInfo.setDataStores(dataStores);/*from  w ww . j  a v a2s  .c  o  m*/
    configService.updateTypeInfoForPV(pvName, typeInfo);
    configService.registerPVToAppliance(pvName, configService.getMyApplianceInfo());
    configService.getETLLookup().manualControlForUnitTests();
    //generate datas of 10 days PB file 2012_01_01.pb  to 2012_01_10.pb
    int dayCount = 10;
    for (int day = 0; day < dayCount; day++) {
        logger.debug("Generating data for day " + 1);
        int startofdayinseconds = day * 24 * 60 * 60;
        int runsperday = 12;
        int eventsperrun = 24 * 60 * 60 / runsperday;
        for (int currentrun = 0; currentrun < runsperday; currentrun++) {
            try (BasicContext context = new BasicContext()) {
                logger.debug("Generating data for run " + currentrun);

                YearSecondTimestamp yts = new YearSecondTimestamp(currentYear, (day + 1) * 24 * 60 * 60, 0);
                Timestamp etlTime = TimeUtils.convertFromYearSecondTimestamp(yts);
                logger.debug("Running ETL as if it were " + TimeUtils.convertToHumanReadableString(etlTime));
                ETLExecutor.runETLs(configService, etlTime);
                ArrayListEventStream testData = new ArrayListEventStream(eventsperrun,
                        new RemotableEventStreamDesc(type, pvName, currentYear));
                for (int secondsinrun = 0; secondsinrun < eventsperrun; secondsinrun++) {
                    testData.add(
                            new SimulationEvent(startofdayinseconds + currentrun * eventsperrun + secondsinrun,
                                    currentYear, type, new ScalarValue<Double>((double) secondsinrun)));
                }
                storageplugin1.appendData(context, pvName, testData);
            }
            // Sleep for a couple of seconds so that the modification times are different.
            Thread.sleep(2 * 1000);
        }
    } // end for 

    File shortTermFIle = new File(shortTermFolderName);
    File mediumTermFIle = new File(mediumTermFolderName);
    //File longTermFIle=new File(longTermFolderName);

    String[] filesShortTerm = shortTermFIle.list();
    String[] filesMediumTerm = mediumTermFIle.list();
    assertTrue("there should be PB files int short term storage but there is no ", filesShortTerm.length != 0);
    assertTrue("there should be PB files int medium term storage but there is no ",
            filesMediumTerm.length != 0);
    //ArchUnitTestConsolidateETLJobsForOnePVTest:_pb.zip
    File zipFileOflongTermFile = new File(longTermFolderName + "/" + pvName + ":_pb.zip");
    assertTrue(longTermFolderName + "/" + pvName + ":_pb.zip shoule exist but it doesn't",
            zipFileOflongTermFile.exists());
    ZipFile lastZipFile1 = new ZipFile(zipFileOflongTermFile);
    Enumeration<ZipArchiveEntry> enumeration1 = lastZipFile1.getEntries();
    int ss = 0;
    while (enumeration1.hasMoreElements()) {
        enumeration1.nextElement();
        ss++;
    }
    assertTrue(
            "the zip file of " + longTermFolderName + "/" + pvName
                    + ":_pb.zip should contain pb files less than " + dayCount + ",but the number is " + ss,
            ss < dayCount);
    // consolidate
    String storageName = "LTS";
    Timestamp oneYearLaterTimeStamp = TimeUtils
            .convertFromEpochSeconds(TimeUtils.getCurrentEpochSeconds() + 365 * 24 * 60 * 60, 0);
    // The ConfigServiceForTests automatically adds a ETL Job for each PV. For consolidate, we need to have "paused" the PV; we fake this by deleting the jobs.
    configService.getETLLookup().deleteETLJobs(pvName);
    ETLExecutor.runPvETLsBeforeOneStorage(configService, oneYearLaterTimeStamp, pvName, storageName);
    // make sure there are no pb files in short term storage , medium term storage and all files in long term storage
    Thread.sleep(4000);
    String[] filesShortTerm2 = shortTermFIle.list();
    String[] filesMediumTerm2 = mediumTermFIle.list();
    assertTrue("there should be no files int short term storage but there are still " + filesShortTerm2.length
            + "PB files", filesShortTerm2.length == 0);
    assertTrue("there should be no files int medium term storage but there are still " + filesMediumTerm2.length
            + "PB files", filesMediumTerm2.length == 0);
    //ArchUnitTestConsolidateETLJobsForOnePVTest:_pb.zip
    File zipFileOflongTermFile2 = new File(longTermFolderName + "/" + pvName + ":_pb.zip");
    assertTrue(longTermFolderName + "/" + pvName + ":_pb.zip shoule exist but it doesn't",
            zipFileOflongTermFile2.exists());

    ZipFile lastZipFile = new ZipFile(zipFileOflongTermFile2);
    Enumeration<ZipArchiveEntry> enumeration = lastZipFile.getEntries();
    ZipEntry zipEntry = null;
    HashMap<String, String> fileNameMap = new HashMap<String, String>();
    while (enumeration.hasMoreElements()) {
        zipEntry = (ZipEntry) enumeration.nextElement();

        String fileNameTemp = zipEntry.getName();
        logger.info("fileName1=" + fileNameTemp);

        int indexPB = fileNameTemp.indexOf(".pb");
        int indexDate = indexPB - 5;
        String dateFileName = fileNameTemp.substring(indexDate, indexPB);
        fileNameMap.put(dateFileName, dateFileName);
        //System.out.println("fileName="+dateFileName);
        logger.info("fileName=" + dateFileName);
    }

    assertTrue("The number of files should be " + dayCount + ", acutuallly, it is " + fileNameMap.size(),
            fileNameMap.size() == dayCount);
    Date beinningDate = new Date();
    beinningDate.setYear(currentYear - 1);
    beinningDate.setMonth(11);
    beinningDate.setDate(31);
    logger.info("currentYear=" + currentYear);
    logger.info("beinningDate=" + beinningDate);
    Calendar calendarBeingining = Calendar.getInstance();
    calendarBeingining.setTime(beinningDate);
    SimpleDateFormat df = new SimpleDateFormat("MM_dd");
    for (int m = 0; m < dayCount; m++) {
        calendarBeingining.add(Calendar.DAY_OF_MONTH, 1);
        String fileNameTemp1 = df.format(calendarBeingining.getTime());
        logger.info("fileNameTemp1=" + fileNameTemp1);
        assertTrue("the file  whose name is like " + pvName + ":" + currentYear + "_" + fileNameTemp1
                + ".pb should exist,but it doesn't", fileNameMap.get(fileNameTemp1) != null);
    }

}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.FormUpdateAction.java

public void doCommentInput(FlowSheetItem item, EctMeasurementTypesBean mtypeBean,
        MeasurementFlowSheet mFlowsheet, String inputType, String mInstructions, String comment, String date,
        String apptNo, HttpServletRequest request) {
    String temp = request.getParameter("template");
    String demographicNo = request.getParameter("demographic_no");
    HttpSession session = request.getSession();
    String providerNo = (String) session.getAttribute("user");
    String comments = comment;//from  w w w  .j  a  v a  2 s .  com

    String dateObserved = date;

    java.util.Calendar calender = java.util.Calendar.getInstance();
    String hour = Integer.toString(calender.get(java.util.Calendar.HOUR_OF_DAY));
    String min = Integer.toString(calender.get(java.util.Calendar.MINUTE));
    String second = Integer.toString(calender.get(java.util.Calendar.SECOND));
    String dateEntered = dateObserved + " " + hour + ":" + min + ":" + second;

    comments = org.apache.commons.lang.StringEscapeUtils.escapeSql(comments);
    MsgStringQuote str = new MsgStringQuote();
    ResultSet rs;

    String[] dateComp = date.split("-");
    Date dateObs = new Date();
    dateObs.setYear(Integer.parseInt(dateComp[0]) - 1900);
    dateObs.setMonth(Integer.parseInt(dateComp[1]) - 1);
    dateObs.setDate(Integer.parseInt(dateComp[2]));

    MeasurementDao measurementDao = (MeasurementDao) SpringUtils.getBean("measurementDao");

    Measurement measurement = new Measurement();
    measurement.setDemographicId(Integer.parseInt(demographicNo));
    measurement.setDataField("");
    measurement.setMeasuringInstruction(mInstructions);
    measurement.setComments(comments);
    measurement.setDateObserved(dateObs);
    measurement.setType(inputType);
    if (apptNo != null) {
        measurement.setAppointmentNo(Integer.parseInt(apptNo));
    } else {
        measurement.setAppointmentNo(0);
    }
    measurement.setProviderNo(providerNo);

    measurementDao.persist(measurement);

}

From source file:accountgen.controller.Controller.java

private void getListTags(Document doc, Person p) {
    Elements li = doc.select(".extra").select("li:not(.lab)");
    p.setUsername(li.get(2).text());//  w w w .  j  a  va 2 s.  com
    p.setPassword(li.get(3).text());
    p.setMmn(li.get(4).text());
    p.setMastercard(li.get(6).text());
    p.setSsn("");
    Date d = new Date();
    d.setDate(1);
    d.setYear(Integer.parseInt(li.get(7).text().split("/")[1]) - 1900);
    d.setMonth(Integer.parseInt(li.get(7).text().split("/")[0]) - 1);
    p.setExpires(d);
    p.setCvv2(li.get(8).text());
    p.setFavoritecolor(li.get(9).text());
    p.setOccupation(li.get(10).text());
    p.setCompany(li.get(11).text());
    p.setWebsite(li.get(12).text());
    Vehicle v = new Vehicle();
    v.setModel(li.get(13).text().split(" ")[li.get(13).text().split(" ").length - 1].trim());
    v.setYear(Integer.parseInt(li.get(13).text().split(" ")[0].trim()));
    v.setBrand(
            li.get(13).text().replace(li.get(13).text().split(" ")[li.get(13).text().split(" ").length - 1], "")
                    .replace(li.get(13).text().split(" ")[0], "").trim());
    p.setVehicle(v);
    p.setUpsnr(li.get(14).text());
    p.setBloodtype(li.get(15).text());
    p.setWeight(li.get(16).text().split("\\(")[1].split(" ")[0]);
    p.setHeight(li.get(17).text().split("\\(")[1].split(" ")[0]);
    p.setGuid(li.get(18).text());
}