Example usage for java.util GregorianCalendar GregorianCalendar

List of usage examples for java.util GregorianCalendar GregorianCalendar

Introduction

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

Prototype

public GregorianCalendar() 

Source Link

Document

Constructs a default GregorianCalendar using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.openmrs.contrib.metadatarepository.util.DateConverterTest.java

public void testConvertStringToDate() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);/* w  w  w .jav  a  2s .  c om*/
    final String datePart = DateUtil.convertDateToString(today);
    // test empty time
    Date date = (Date) converter.convert(Date.class, "");
    assertNull(date);
    date = (Date) converter.convert(Date.class, datePart);

    final Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
}

From source file:model.listini.Period.java

public Integer getEndYear() {
    Calendar calendar = new GregorianCalendar();

    calendar.setTime(this.getEndDate());
    return calendar.get(Calendar.YEAR);
}

From source file:com.nabla.wapp.server.general.Util.java

public static Calendar dateToCalendar(final Date dt) {
    final Calendar ret = new GregorianCalendar();
    ret.setTime(dt);/*  www  . j a  v  a2s .c  o m*/
    return ret;
}

From source file:com.strider.datadefender.extensions.BiographicFunctions.java

/**
 * Generates random 9-digit social insurance number
 * @return String/*from  w ww.j a  v  a 2  s .  co m*/
 * @throws java.text.ParseException
 */
public java.sql.Date randomBirthDate() throws java.text.ParseException {
    final GregorianCalendar gc = new GregorianCalendar();
    final int year = randBetween(1900, 2016);

    gc.set(GregorianCalendar.YEAR, year);

    final int dayOfYear = randBetween(1, gc.getActualMaximum(GregorianCalendar.DAY_OF_YEAR));

    gc.set(GregorianCalendar.DAY_OF_YEAR, dayOfYear);

    final String birthDate = prependZero(gc.get(GregorianCalendar.DAY_OF_MONTH)) + "-"
            + prependZero(gc.get(GregorianCalendar.MONTH) + 1) + "-" + gc.get(GregorianCalendar.YEAR);

    log.debug("BirthDate:[" + birthDate + "]");

    final DateFormat format = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
    final java.sql.Date date = new java.sql.Date(format.parse(birthDate).getTime());

    log.debug("Generated BirthDate:[" + date.toString() + "]");

    return date;
}

From source file:org.appverse.web.framework.backend.frontfacade.json.controllers.JSONDateSerializer.java

@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    long millis = date.getTime();
    Date currentDate = new Date();
    Calendar cal = new GregorianCalendar();
    cal.setTime(currentDate);// w w w.  j  a  v  a 2  s .c o m
    int offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
    gen.writeNumber(millis + offset);
}

From source file:com.mycollab.db.persistence.service.DefaultCrudService.java

@Override
public Integer saveWithSession(T record, String username) {
    if (!StringUtils.isBlank(username)) {
        try {/* w w  w  . j  ava2s.  c o m*/
            PropertyUtils.setProperty(record, "createduser", username);
        } catch (Exception e) {
        }
    }

    try {
        PropertyUtils.setProperty(record, "createdtime", new GregorianCalendar().getTime());
        PropertyUtils.setProperty(record, "lastupdatedtime", new GregorianCalendar().getTime());
    } catch (Exception e) {
    }

    getCrudMapper().insertAndReturnKey(record);
    try {
        return (Integer) PropertyUtils.getProperty(record, "id");
    } catch (Exception e) {
        return 0;
    }
}

From source file:airport.services.dispatcher.GeneratorFlightImpl.java

private void createNewJobAndTrigger() {
    JobDataMap dataMap = new JobDataMap();

    dataMap.put(PARAMETER_FMTDAO_NAME, flyingMachineTypeDao);
    dataMap.put(PARAMETER_GENFLIGHTJMS_NAME, jMS);

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(GregorianCalendar.SECOND, DELAY_TIMER_SEC);

    jobDetailFlight = newJob(JobAddFlight.class).withIdentity(SCHEDULE_JOBDET_NAME, SCHEDULE_GROUP_NAME)
            .setJobData(dataMap).build();

    triggerFlight = newTrigger().withIdentity(SCHEDULE_TRIGGER_NAME, SCHEDULE_GROUP_NAME)
            .startAt(calendar.getTime()).withSchedule(SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInSeconds(DELAY_TIMER_SEC).repeatForever())
            .build();//www  .  ja  v  a  2s . co m
}

From source file:be.fedict.eid.pkira.common.util.FilterHelperBean.java

private Date changeTime(Date date, int hours, int minutes, int seconds) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);/*  w  w  w .  j  a v  a 2  s .c  o m*/
    calendar.set(Calendar.HOUR, hours);
    calendar.set(Calendar.MINUTE, minutes);
    calendar.set(Calendar.SECOND, seconds);

    return calendar.getTime();
}

From source file:com.splicemachine.db.iapi.types.SQLDateTest.java

@Test
public void serdeValueData() throws Exception {
    UnsafeRow row = new UnsafeRow(1);
    UnsafeRowWriter writer = new UnsafeRowWriter(new BufferHolder(row), 1);
    Date date = new Date(System.currentTimeMillis());
    int computeEncodedDate = SQLDate.computeEncodedDate(date);
    SQLDate value = new SQLDate(date);
    SQLDate valueA = new SQLDate();
    value.write(writer, 0);//from ww w . ja va2 s .  c  o m
    Assert.assertEquals("SerdeIncorrect", computeEncodedDate, row.getInt(0));
    valueA.read(row, 0);
    Assert.assertEquals("SerdeIncorrect", date.toString(), valueA.getDate(new GregorianCalendar()).toString());
}

From source file:ether.RDFHelper.java

public static Model create(String jsonInput, String date) {
    JSONObject jso = new JSONObject(jsonInput);
    String today = "";
    String yesterday = "";
    String etherSchemaFileName = "ether-schema.ttl";
    Model model = ModelFactory.createDefaultModel();
    model.read(etherSchemaFileName, "TURTLE");

    try {//from w w w  . ja  v a  2  s.co  m
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar temp = new GregorianCalendar();
        temp.setTime(sdf.parse(date));
        temp.add(Calendar.DAY_OF_MONTH, -1);
        yesterday = sdf.format(temp.getTime());
        today = date;
    } catch (Exception e) {
        e.printStackTrace();
    }

    String qualityToday = jso.getString("gentoday").trim();
    String qualityYesterday = jso.getString("genyest").trim();

    if (levelMap.containsKey(qualityToday)) {

        Resource todayEstimate = model.createResource();
        Resource rdfType = ResourceFactory
                .createResource("http://med.auth.gr/lomi/ether-schema#AirPollutionQualityEstimate");
        todayEstimate.addProperty(RDF.type, rdfType);

        Property estimateForNetwork = ResourceFactory
                .createProperty("http://med.auth.gr/lomi/ether-schema#estimateForNetwork");
        Resource network = ResourceFactory.createResource(
                "http://med.auth.gr/lomi/ether-schema#ThessalonikiMunicipalAirPollutionMeasurementNetwork");
        todayEstimate.addProperty(estimateForNetwork, network);

        Property measurementDate = ResourceFactory
                .createProperty("http://med.auth.gr/lomi/ether-schema#measurementDate");
        model.add(todayEstimate, measurementDate,
                ResourceFactory.createTypedLiteral(today, XSDDatatype.XSDdate));

        Property qualityEstimateValue = ResourceFactory
                .createProperty("http://med.auth.gr/lomi/ether-schema#qualityEstimateValue");
        Resource value = ResourceFactory
                .createResource("http://med.auth.gr/lomi/ether-schema#" + levelMap.get(qualityToday));
        todayEstimate.addProperty(qualityEstimateValue, value);
    }

    if (levelMap.containsKey(qualityYesterday)) {

        Resource yesterdayEstimate = model.createResource();
        Resource rdfType = ResourceFactory
                .createResource("http://med.auth.gr/lomi/ether-schema#AirPollutionQualityEstimate");
        yesterdayEstimate.addProperty(RDF.type, rdfType);

        Property estimateForNetwork = ResourceFactory
                .createProperty("http://med.auth.gr/lomi/ether-schema#estimateForNetwork");
        Resource network = ResourceFactory.createResource(
                "http://med.auth.gr/lomi/ether-schema#ThessalonikiMunicipalAirPollutionMeasurementNetwork");
        yesterdayEstimate.addProperty(estimateForNetwork, network);

        Property measurementDate = ResourceFactory
                .createProperty("http://med.auth.gr/lomi/ether-schema#measurementDate");
        model.add(yesterdayEstimate, measurementDate,
                ResourceFactory.createTypedLiteral(yesterday, XSDDatatype.XSDdate));

        Property qualityEstimateValue = ResourceFactory
                .createProperty("http://med.auth.gr/lomi/ether-schema#qualityEstimateValue");
        Resource value = ResourceFactory
                .createResource("http://med.auth.gr/lomi/ether-schema#" + levelMap.get(qualityYesterday));
        yesterdayEstimate.addProperty(qualityEstimateValue, value);
    }

    for (String keyP : pollutantDailyMap.keySet()) {
        for (String keyS : stationMap.keySet()) {
            String jsonKey = keyP + "_" + keyS;
            try {
                Double value = jso.getDouble(jsonKey);
                Resource dailyMeasurement = model.createResource();

                Resource rdfType = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#AverageDailyMeasurement");
                dailyMeasurement.addProperty(RDF.type, rdfType);

                Property measurementDate = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementDate");
                model.add(dailyMeasurement, measurementDate,
                        ResourceFactory.createTypedLiteral(yesterday, XSDDatatype.XSDdate));

                Property measurementFromStation = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementFromStation");
                Resource station = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#" + stationMap.get(keyS));
                dailyMeasurement.addProperty(measurementFromStation, station);

                Property measurementOfPollutant = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementOfPollutant");
                Resource pollutant = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#" + pollutantDailyMap.get(keyP));
                dailyMeasurement.addProperty(measurementOfPollutant, pollutant);

                Property measurementValue = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementValue");
                model.add(dailyMeasurement, measurementValue,
                        ResourceFactory.createTypedLiteral(value.toString(), XSDDatatype.XSDfloat));

                Property quantity = ResourceFactory.createProperty("http://qudt.org/schema/qudt#quantity");
                Resource density = ResourceFactory.createResource("http://qudt.org/vocab/quantity#Density");
                model.add(dailyMeasurement, quantity, density);

                Property unit = ResourceFactory.createProperty("http://qudt.org/schema/qudt#unit");
                Resource micro = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#MicrogramPerCubicMeter");
                Resource milli = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#MilligramPerCubicMeter");
                if (keyP.equals("co")) {
                    model.add(dailyMeasurement, unit, milli);
                } else {
                    model.add(dailyMeasurement, unit, micro);
                }
            } catch (Exception e) {
                //nothing
            }
        }
    }
    for (String keyP : pollutantHourlyMap.keySet()) {
        for (String keyS : stationMap.keySet()) {
            String jsonKey = keyP + "_" + keyS;
            try {
                Double value = jso.getDouble(jsonKey);
                Resource hourlyMeasurement = model.createResource();

                Resource rdfType = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#MaximumHourlyMeasurement");
                hourlyMeasurement.addProperty(RDF.type, rdfType);

                Property measurementDate = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementDate");
                model.add(hourlyMeasurement, measurementDate,
                        ResourceFactory.createTypedLiteral(today, XSDDatatype.XSDdate));

                Property measurementFromStation = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementFromStation");
                Resource station = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#" + stationMap.get(keyS));
                hourlyMeasurement.addProperty(measurementFromStation, station);

                Property measurementOfPollutant = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementOfPollutant");
                Resource pollutant = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#" + pollutantHourlyMap.get(keyP));
                hourlyMeasurement.addProperty(measurementOfPollutant, pollutant);

                Property measurementValue = ResourceFactory
                        .createProperty("http://med.auth.gr/lomi/ether-schema#measurementValue");
                model.add(hourlyMeasurement, measurementValue,
                        ResourceFactory.createTypedLiteral(value.toString(), XSDDatatype.XSDfloat));

                Property quantity = ResourceFactory.createProperty("http://qudt.org/schema/qudt#quantity");
                Resource density = ResourceFactory.createResource("http://qudt.org/vocab/quantity#Density");
                model.add(hourlyMeasurement, quantity, density);

                Property unit = ResourceFactory.createProperty("http://qudt.org/schema/qudt#unit");
                Resource micro = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#MicrogramPerCubicMeter");
                Resource milli = ResourceFactory
                        .createResource("http://med.auth.gr/lomi/ether-schema#MilligramPerCubicMeter");
                if (keyP.equals("co")) {
                    model.add(hourlyMeasurement, unit, milli);
                } else {
                    model.add(hourlyMeasurement, unit, micro);
                }
            } catch (Exception e) {
                //nothing
            }
        }
    }

    return model;
}