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:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java

@Override
public EBusDateTime decodeInt(byte[] data) throws EBusTypeException {

    if (data == null) {
        // TODO replace value
        return null;
    }//  w w  w  . jav  a 2s  .com

    IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD);
    IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD);
    IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR);

    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    BigDecimal day = null;
    BigDecimal month = null;
    BigDecimal year = null;

    if (data.length != getTypeLength()) {
        throw new EBusTypeException(
                String.format("Input byte array must have a length of %d bytes!", getTypeLength()));
    }

    if (StringUtils.equals(variant, SHORT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, DEFAULT)) {
        day = bcdType.decode(new byte[] { data[0] });
        month = bcdType.decode(new byte[] { data[1] });
        year = bcdType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, HEX_SHORT)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, HEX)) {
        day = charType.decode(new byte[] { data[0] });
        month = charType.decode(new byte[] { data[1] });
        year = charType.decode(new byte[] { data[3] });

    } else if (StringUtils.equals(variant, DAYS)) {
        BigDecimal daysSince1900 = wordType.decode(data);
        calendar.set(1900, 0, 1, 0, 0);
        calendar.add(Calendar.DAY_OF_YEAR, daysSince1900.intValue());
    }

    if (day != null && month != null && year != null) {
        if (day.intValue() < 1 || day.intValue() > 31) {
            throw new EBusTypeException("A valid day must be in a range between 1-31 !");
        }
        if (month.intValue() < 1 || month.intValue() > 12) {
            throw new EBusTypeException("A valid day must be in a range between 1-12 !");
        }
    }

    if (year != null) {
        if (year.intValue() < 70) {
            year = year.add(new BigDecimal(2000));
        } else {
            year = year.add(new BigDecimal(1900));
        }
        calendar.set(Calendar.YEAR, year.intValue());
    }

    if (month != null) {
        calendar.set(Calendar.MONTH, month.intValue() - 1);
    }

    if (day != null && day.intValue() > 0 && day.intValue() < 32) {
        calendar.set(Calendar.DAY_OF_MONTH, day.intValue());
    }

    return new EBusDateTime(calendar, false, true);
}

From source file:de.dlopes.stocks.facilitator.data.StockInfo.java

public StockInfo(String isin) {
    this.isin = isin;

    // TODO: move
    this.lastChanged = new GregorianCalendar();
}

From source file:DateUtils.java

public static final String getTimeFromDate(Date dt) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(dt);/*from  ww w.ja v a 2  s .c om*/

    StringBuffer ret = new StringBuffer();
    ret.append(cal.get(Calendar.HOUR));
    ret.append(":");
    ret.append(cal.get(Calendar.MINUTE));

    return ret.toString();
}

From source file:nl.xillio.gitbreakers.procrastimaster.server.services.UpdateService.java

private void setNextWorkingDayToMidnight(Update entity) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(entity.getNextDay());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    entity.setNextDay(calendar.getTime());
}

From source file:com.esofthead.mycollab.common.service.ibatis.CustomViewStoreServiceImpl.java

@Override
public void saveOrUpdateViewLayoutDef(CustomViewStore viewStore) {
    CustomViewStore viewLayoutDef = getViewLayoutDef(viewStore.getSaccountid(), viewStore.getCreateduser(),
            viewStore.getViewid());//from  ww w. ja  v  a2  s  .  co m
    viewStore.setCreatedtime(new GregorianCalendar().getTime());
    if (!(viewLayoutDef instanceof NullCustomViewStore)) {
        viewStore.setId(viewLayoutDef.getId());
        updateWithSession(viewStore, viewStore.getCreateduser());
    } else {
        saveWithSession(viewStore, viewStore.getCreateduser());
    }
}

From source file:de.arago.rike.task.action.StartTask.java

@Override
public void execute(IDataWrapper data) throws Exception {
    if (data.getRequestAttribute("id") != null) {
        String user = SecurityHelper.getUserEmail(data.getUser());

        if (TaskHelper.getTasksInProgressForUser(user).size() < Integer
                .parseInt(GlobalConfig.get(WORKFLOW_WIP_LIMIT))) {
            Task task = TaskHelper.getTask(data.getRequestAttribute("id"));

            if (!TaskHelper.canDoTask(user, task) || task.getStatusEnum() != Task.Status.OPEN) {
                return;
            }/*from   w w w .java 2s.c om*/

            task.setOwner(user);
            task.setStart(new Date());
            task.setStatus(Task.Status.IN_PROGRESS);
            if (GlobalConfig.get(WORKFLOW_TYPE).equalsIgnoreCase("arago Technologies")) {
                GregorianCalendar c = new GregorianCalendar();
                c.setTime(task.getStart());
                c.add(Calendar.DAY_OF_MONTH, Integer.parseInt(GlobalConfig.get(WORKFLOW_DAYS_TO_FINISH_TASK)));
                task.setDueDate(c.getTime());
            }

            TaskHelper.save(task);
            StatisticHelper.update();

            data.setSessionAttribute("task", task);

            HashMap<String, Object> notificationParam = new HashMap<String, Object>();

            notificationParam.put("id", task.getId().toString());
            data.setEvent("TaskUpdateNotification", notificationParam);

            ActivityLogHelper.log(
                    " started Task #" + task.getId() + " <a href=\"/web/guest/rike/-/show/task/" + task.getId()
                            + "\">" + StringEscapeUtils.escapeHtml(task.getTitle()) + "</a> ",
                    task.getStatus(), user, data, task.toMap());
        }
    }
}

From source file:org.openmrs.module.usagestatistics.web.view.chart.DateRangeChartView.java

@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    UsageStatisticsService svc = Context.getService(UsageStatisticsService.class);
    List<Object[]> stats = svc.getDateRangeStats(null, null, null);

    String xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.date");
    String yAxisLabel = ContextProvider.getMessage("usagestatistics.chart.records");
    String seriesUsages = ContextProvider.getMessage("usagestatistics.results.views");
    String seriesEncounters = ContextProvider.getMessage("usagestatistics.results.encounters");
    String seriesUpdates = ContextProvider.getMessage("usagestatistics.results.updates");

    // Get minimum date value in returned statistics
    Date minDate = (stats.size() > 0) ? (Date) (stats.get(0)[0]) : getFromDate();
    if (minDate.getTime() > getFromDate().getTime()) // Min date must be at least a week ago
        minDate = getFromDate();/* ww  w  . ja  va 2  s .c o m*/
    // Maximum date defaults to today
    Date maxDate = (getUntilDate() != null) ? getUntilDate() : new Date();

    // Build a zeroized dataset of all dates in range       
    TimeTableXYDataset dataset = new TimeTableXYDataset();
    Calendar cal = new GregorianCalendar();
    cal.setTime(minDate);
    while (cal.getTime().getTime() <= maxDate.getTime()) {
        Date day = cal.getTime();
        dataset.add(new Day(day), 0, seriesUsages, false);
        dataset.add(new Day(day), 0, seriesEncounters, false);
        dataset.add(new Day(day), 0, seriesUpdates, false);
        cal.add(Calendar.DATE, 1);
    }

    // Update the dates for which we have statistics
    for (Object[] row : stats) {
        Date date = (Date) row[0];
        int usages = ((Number) row[1]).intValue();
        int encounters = ((Number) row[2]).intValue();
        int updates = ((Number) row[3]).intValue();
        dataset.add(new Day(date), usages, seriesUsages, false);
        dataset.add(new Day(date), encounters, seriesEncounters, false);
        dataset.add(new Day(date), updates, seriesUpdates, false);
    }
    dataset.setDomainIsPointsInTime(true);

    JFreeChart chart = ChartFactory.createXYLineChart(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, false, false);
    DateAxis xAxis = new DateAxis(xAxisLabel);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainAxis(xAxis);

    return chart;
}

From source file:ch.puzzle.itc.mobiliar.business.generator.control.extracted.ResourceDependencyResolverServiceTest.java

@Before
public void before() {
    service.resourceReleaseComparator = new ResourceReleaseComparator();

    Calendar cal = new GregorianCalendar();

    cal.set(2001, Calendar.JANUARY, 1);
    release1 = createRelease(1, new Date(cal.getTimeInMillis()));

    cal.set(2002, Calendar.JANUARY, 1);
    release2 = createRelease(2, new Date(cal.getTimeInMillis()));

    cal.set(2003, Calendar.JANUARY, 1);
    release3 = createRelease(3, new Date(cal.getTimeInMillis()));

    cal.set(2004, Calendar.JANUARY, 1);
    release4 = createRelease(4, new Date(cal.getTimeInMillis()));

    r1 = ResourceEntityBuilder.createResourceEntity("test1", 1);
    r1.setRelease(release1);//from w w w . ja  va  2 s .c o  m

    r2 = ResourceEntityBuilder.createResourceEntity("test2", 2);
    r2.setRelease(release2);

    r3 = ResourceEntityBuilder.createResourceEntity("test3", 3);
    r3.setRelease(release3);

    r4 = ResourceEntityBuilder.createResourceEntity("test4", 4);
    r4.setRelease(release4);

}

From source file:org.psidnell.omnifocus.expr.ExpressionFunctionsTest.java

@Test
public void testDays() {

    Calendar today = new GregorianCalendar();
    ExpressionFunctions.roundToDay(today);

    Calendar yesterday = new GregorianCalendar();
    ExpressionFunctions.roundToDay(yesterday);
    yesterday.set(Calendar.DAY_OF_MONTH, yesterday.get(Calendar.DAY_OF_MONTH) - 1);

    Calendar tomorrow = new GregorianCalendar();
    ExpressionFunctions.roundToDay(tomorrow);
    tomorrow.set(Calendar.DAY_OF_MONTH, tomorrow.get(Calendar.DAY_OF_MONTH) + 1);

    assertEquals(today.getTime(), fn.days(0, clone(today)));
    assertEquals(yesterday.getTime(), fn.days(-1, clone(today)));
    assertEquals(tomorrow.getTime(), fn.days(1, clone(today)));

}

From source file:com.esofthead.mycollab.core.persistence.service.DefaultCrudService.java

@Override
public int updateWithSession(T record, String username) {
    try {/*  w ww  .  ja v  a  2s . c  om*/
        PropertyUtils.setProperty(record, "lastupdatedtime", new GregorianCalendar().getTime());
    } catch (Exception e) {
    }

    if (cacheUpdateMethod == null) {
        findCacheUpdateMethod();
    }
    try {
        cacheUpdateMethod.invoke(getCrudMapper(), record);
        return 1;
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new MyCollabException(e);
    }
}