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.psidnell.omnifocus.expr.ExpressionFunctionsTest.java

@Test
public void testCalendarRoundToDay() throws ParseException {
    Date date1 = ExpressionFunctions.roundToDay(new Date());

    Calendar cal2 = new GregorianCalendar();

    assertNotEquals(date1, cal2.getTime());

    ExpressionFunctions.roundToDay(cal2);

    assertEquals(date1, cal2.getTime());
}

From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java

public MainConfigBackingBean(EhourConfigStub config) {
    this.config = config;

    smtpAuthentication = StringUtils.isNotBlank(config.getSmtpUsername())
            && StringUtils.isNotBlank(config.getSmtpPassword());

    Calendar cal = new GregorianCalendar();
    DateUtil.dayOfWeekFix(cal);/*from w w  w  .  j ava  2 s.co m*/
    cal.set(Calendar.DAY_OF_WEEK, config.getFirstDayOfWeek());
    firstWeekStart = cal.getTime();

    splitCronExpression(config.getReminderTime());
    updateReminderCronExpression();
}

From source file:org.ow2.petals.cloud.vacation.web.services.VacationClient.java

public String create(final String enquirer, final PendingVacationRequest newRequest) {
    assert enquirer != null;
    assert newRequest != null;

    final VacationRequestType request = new VacationRequestType();
    request.setDayNumber(newRequest.getDayNumber());
    request.setEnquirer(enquirer);//from   ww  w . j  av a2s.  c  om
    request.setReason(newRequest.getReason());

    final GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(newRequest.getStartDate());
    request.setStartDate(dtf.newXMLGregorianCalendar(cal));

    return ((NewVacationResponse) getWebServiceTemplate().marshalSendAndReceive(
            requestOF.createVacationRequest(request),
            new SoapActionCallback("http://petals.ow2.org/samples/se-bpmn/vacationService/newVacationRequest")))
                    .getVacationRequestId();
}

From source file:ma.glasnost.orika.test.converter.CloneableConverterNoSetAccessibleTestCase.java

@Test
public void cloneableConverterWithoutSetAccessible() throws DatatypeConfigurationException {

    final SecurityManager initialSm = System.getSecurityManager();
    try {// w w w. j  a  v a 2s. co  m
        System.setSecurityManager(new SecurityManager() {
            public void checkPermission(java.security.Permission perm) {
                if ("suppressAccessChecks".equals(perm.getName())) {
                    for (StackTraceElement ste : new Throwable().getStackTrace()) {
                        if (ste.getClassName().equals(CloneableConverter.class.getCanonicalName())) {
                            throw new SecurityException("not permitted");
                        }
                    }
                }
            }
        });

        CloneableConverter cc = new CloneableConverter(SampleCloneable.class);

        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(cc);

        GregorianCalendar cal = new GregorianCalendar();
        cal.add(Calendar.YEAR, 10);
        XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar((GregorianCalendar) cal);
        cal.add(Calendar.MONTH, 3);

        ClonableHolder source = new ClonableHolder();
        source.value = new SampleCloneable();
        source.value.id = 5L;
        source.date = new Date(System.currentTimeMillis() + 100000);
        source.timestamp = new Timestamp(System.currentTimeMillis() + 50000);
        source.calendar = cal;
        source.xmlCalendar = xmlCal;

        ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class);
        Assert.assertEquals(source.value, dest.value);
        Assert.assertNotSame(source.value, dest.value);
        Assert.assertEquals(source.date, dest.date);
        Assert.assertNotSame(source.date, dest.date);
        Assert.assertEquals(source.timestamp, dest.timestamp);
        Assert.assertNotSame(source.timestamp, dest.timestamp);
        Assert.assertEquals(source.calendar, dest.calendar);
        Assert.assertNotSame(source.calendar, dest.calendar);
        Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar);
        Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar);
    } finally {
        System.setSecurityManager(initialSm);
    }
}

From source file:org.jasig.portlet.ClassifiedsPortlet.service.AdGroomer.java

@Override
public void run() {
    Date now;//from  w  w w  .  j a va2  s .c om
    Calendar nowCal = new GregorianCalendar();
    long lastCheckTime = System.currentTimeMillis();
    boolean firstCheck = true;

    while (bRun) {
        now = new Date();
        nowCal.setTime(now);

        if (nowCal.get(Calendar.HOUR_OF_DAY) == hourToCheck
                && nowCal.get(Calendar.MINUTE) <= (minuteToCheck + 1)
                && (firstCheck || System.currentTimeMillis() > (lastCheckTime + maxCheckIntervalMillis))) {

            log.info("Ad groomer to delete expired ads at " + now.toString());
            adService.deleteExpiredAds();
            lastCheckTime = System.currentTimeMillis();
            firstCheck = false;
        }
        try {
            log.debug("Ad groomer Waiting to see if we should check the time...");
            sleep(checkInterval * 1000);
        } catch (InterruptedException e) {
            break;
        }
    }
}

From source file:edu.stanford.muse.email.Filter.java

/** takes current date and converts it to something like 20130709 for July 9 2013 */
private static String dateToString(Date d) {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(d);/*from   www.j  av a 2 s. c o m*/
    int yyyy = c.get(Calendar.YEAR);
    int mm = c.get(Calendar.MONTH) + 1; // rememeber + 1 adj cos calendar is 0 based
    int dd = c.get(Calendar.DATE);
    return String.format("%04d", yyyy) + String.format("%02d", mm) + String.format("%02d", dd);
}

From source file:no.dusken.aranea.web.control.HeaderController.java

@RequestMapping("/header.do")
public String handleHeaderMenu(
        @RequestParam(value = "section", required = false, defaultValue = "") String sectionUrl,
        @RequestParam(value = "subsection", required = false, defaultValue = "") String subSectionUrl,
        Model model) {/*from www .j av a  2  s .c o  m*/

    Section section = sectionService.getSectionByUrl(sectionUrl, null);
    model.addAttribute("selectedSection", section);

    if (subSectionUrl != null && !subSectionUrl.equals("")) {
        Section subsection = sectionService.getSectionByUrl(subSectionUrl, section);
        model.addAttribute("selectedSubsection", subsection);
    }

    if (section != null) {
        List<Section> children = section.getActiveChildren();
        if (children != null && children.size() > 0) {
            model.addAttribute("children", children);
        }
    }

    GregorianCalendar now = new GregorianCalendar();
    model.addAttribute("now", now);
    List<Section> sections = sectionService.getTopLevelSections(false);
    model.addAttribute("sections", sections);
    model.addAttribute("years", now.get(Calendar.YEAR) - 1914);
    return "no/dusken/aranea/base/web/header/view";
}

From source file:org.seedstack.monitoring.batch.internal.rest.jobexecution.JobExecutionResource.java

/**
 * Retrieves the list of job executions by job name.
 *
 * @param jobName  the job name//w w  w  . j ava  2 s  . com
 * @param pageSize the size of the result page
 * @return the list of {@link JobExecutionInfo}
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions("seed:monitoring:batch:read")
public Response jobExecutionsByJobName(@PathParam("jobName") String jobName,
        @DefaultValue("1") @QueryParam("pageIndex") int pageIndex,
        @DefaultValue("1000") @QueryParam("pageSize") int pageSize) {

    int startJob = (pageIndex - 1) * pageSize;
    ArrayList<JobExecutionInfo> jobExecutionInfos = new ArrayList<JobExecutionInfo>();
    int totalItems;
    try {
        totalItems = jobService.countJobExecutionsForJob(jobName);
        Collection<JobExecution> jobExecutions = jobService.listJobExecutionsForJob(jobName, startJob,
                pageSize);
        for (JobExecution jobExecution : jobExecutions) {

            JobExecutionInfo jobExecutionInfo = new JobExecutionInfo(jobExecution,
                    new GregorianCalendar().getTimeZone());
            jobExecutionInfos.add(jobExecutionInfo);

        }

    } catch (NoSuchJobException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity("There is no such job (" + jobName + ") ")
                .type(MediaType.TEXT_PLAIN).build();
    }
    JobExecutionRepresentation jobExecutionRepresentation = new JobExecutionRepresentation(pageIndex, pageSize,
            totalItems, jobExecutionInfos);
    return Response.ok(jobExecutionRepresentation).build();
}

From source file:com.gsr.myschool.server.job.impl.ExpiredDossierJobImpl.java

@Override
public void work() {
    SimpleDateFormat dateformat = new SimpleDateFormat(GlobalParameters.DATE_FORMAT);

    logger.info("Job started at " + dateformat.format(new Date()));

    int number = 0;
    DossierFilterDTO filter = new DossierFilterDTO();
    filter.setStatus(DossierStatus.CREATED);

    List<Dossier> dossiers = dossierService.findAllDossiersByCriteria(filter, null, null).getDossiers();

    for (Dossier dossier : dossiers) {
        // ne supprimer que les dossier cres non soumis des filieres generales
        if (dossier.getFiliere() != null
                && dossier.getFiliere().getId().longValue() >= GlobalParameters.PREPA_FILIERE_FROM)
            continue;
        if (dossier.getCreateDate() != null) {
            Calendar date = new GregorianCalendar();
            date.setTime(dossier.getCreateDate());
            date.add(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
            Calendar deleteAfterThis = new GregorianCalendar();

            if (deleteAfterThis.after(date)) {
                logger.info("deleting dossier id : " + dossier.getId() + ".");
                try {
                    inscriptionService.deleteInscription(dossier.getId());
                    number++;/*from   w  w  w.  j a v  a2 s.  c o m*/
                } catch (Exception e) {
                    logger.fatal(e.getMessage());
                }
            }
        }
    }

    logger.info("Job ended at " + dateformat.format(new Date()) + " with " + number + " Dossier deleted");
}

From source file:DateUtils.java

/**
 * Get ISO 8601 timestamp./*from  w ww.j a v a  2s  . c  o  m*/
 */
public final static String getISO8601Date(long millis) {
    StringBuffer sb = new StringBuffer(19);
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(millis);

    // year
    sb.append(cal.get(Calendar.YEAR));

    // month
    sb.append('-');
    int month = cal.get(Calendar.MONTH) + 1;
    if (month < 10) {
        sb.append('0');
    }
    sb.append(month);

    // date
    sb.append('-');
    int date = cal.get(Calendar.DATE);
    if (date < 10) {
        sb.append('0');
    }
    sb.append(date);

    // hour
    sb.append('T');
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    if (hour < 10) {
        sb.append('0');
    }
    sb.append(hour);

    // minute
    sb.append(':');
    int min = cal.get(Calendar.MINUTE);
    if (min < 10) {
        sb.append('0');
    }
    sb.append(min);

    // second
    sb.append(':');
    int sec = cal.get(Calendar.SECOND);
    if (sec < 10) {
        sb.append('0');
    }
    sb.append(sec);

    return sb.toString();
}