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(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second) 

Source Link

Document

Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.

Usage

From source file:org.tsm.concharto.dao.IntegrationTestEventDao.java

@Before
public void setUp() {
    Calendar cal = new GregorianCalendar(107 + 1900, 8, 22, 12, 22, 3);
    cal.set(Calendar.MILLISECOND, 750);
    begin = cal.getTime();/*from  w ww.  j a  v  a  2s  .  c  o m*/
    cal.set(Calendar.SECOND, 35);
    end = cal.getTime();
    getEventTesterDao().deleteAll();
}

From source file:org.openmrs.module.distrotools.test.TestUtils.java

/**
 * Convenience method to create a new date with time
 * @param year the year//from   w w w. j a  va2 s .co m
 * @param month the month
 * @param day the day
 * @param hour the hour
 * @param minute the minute
 * @param second the second
 * @return the date
 * @throws IllegalArgumentException if date values are not valid
 */
public static Date date(int year, int month, int day, int hour, int minute, int second) {
    Calendar cal = new GregorianCalendar(year, month - 1, day, hour, minute, second);
    cal.setLenient(false);
    return cal.getTime();
}

From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeTime.java

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

    Calendar calendar = new GregorianCalendar(1970, 0, 1, 0, 0, 0);

    BigDecimal second = null;/* ww w.  j  ava  2s  .c o  m*/
    BigDecimal minute = null;
    BigDecimal hour = null;

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

    if (StringUtils.equals(variant, SHORT)) {
        IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD);
        minute = bcdType.decode(new byte[] { data[0] });
        hour = bcdType.decode(new byte[] { data[1] });

    } else if (StringUtils.equals(variant, DEFAULT)) {
        IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD);
        second = bcdType.decode(new byte[] { data[0] });
        minute = bcdType.decode(new byte[] { data[1] });
        hour = bcdType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, HEX)) {
        IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR);
        second = charType.decode(new byte[] { data[0] });
        minute = charType.decode(new byte[] { data[1] });
        hour = charType.decode(new byte[] { data[2] });

    } else if (StringUtils.equals(variant, HEX_SHORT)) {
        IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR);
        minute = charType.decode(new byte[] { data[0] });
        hour = charType.decode(new byte[] { data[1] });

    } else if (StringUtils.equals(variant, MINUTES) || StringUtils.equals(variant, MINUTES_SHORT)) {

        BigDecimal minutesSinceMidnight = null;
        if (StringUtils.equals(variant, MINUTES_SHORT)) {
            IEBusType<BigDecimal> type = types.getType(EBusTypeUnsignedNumber.TYPE_UNUMBER, IEBusType.LENGTH,
                    1);
            minutesSinceMidnight = type.decode(data);
        } else {
            IEBusType<BigDecimal> type = types.getType(EBusTypeUnsignedNumber.TYPE_UNUMBER, IEBusType.LENGTH,
                    2);
            minutesSinceMidnight = type.decode(data);
        }

        minutesSinceMidnight = minutesSinceMidnight.multiply(minuteMultiplier);

        if (minutesSinceMidnight.intValue() > 1440) {
            throw new EBusTypeException("Value 'minutes since midnight' to large!");
        }

        calendar.add(Calendar.MINUTE, minutesSinceMidnight.intValue());
    }

    if (second != null) {
        calendar.set(Calendar.SECOND, second.intValue());
    }
    if (minute != null) {
        calendar.set(Calendar.MINUTE, minute.intValue());
    }
    if (hour != null) {
        calendar.set(Calendar.HOUR_OF_DAY, hour.intValue());
    }

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

From source file:org.tsm.concharto.audit.IntegrationTestAuditEntry.java

@Before
public void setUp() {
    Calendar cal = new GregorianCalendar(107 + 1900, 8, 22, 12, 22, 3);
    cal.set(Calendar.MILLISECOND, 750);
    begin = cal.getTime();/*from w  ww. j  a  v  a2  s . c om*/
    cal.set(Calendar.SECOND, 35);
    end = cal.getTime();

}