Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

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

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:org.openvpms.archetype.rules.util.DateRules.java

/**
 * Adds a date and time./*ww  w .j a va2 s .  c  om*/
 *
 * @param date the date part
 * @param time the time to add
 * @return the date+time
 */
public static Date addDateTime(Date date, Date time) {
    GregorianCalendar dateCal = new GregorianCalendar();
    dateCal.setTime(date);
    GregorianCalendar timeCal = new GregorianCalendar();
    timeCal.setTime(time);

    dateCal.set(Calendar.HOUR_OF_DAY, timeCal.get(Calendar.HOUR_OF_DAY));
    dateCal.set(Calendar.MINUTE, timeCal.get(Calendar.MINUTE));
    dateCal.set(Calendar.SECOND, timeCal.get(Calendar.SECOND));
    return dateCal.getTime();
}

From source file:dao.Graficos.java

public static Date dia_inicial_final_semana(boolean isPrimeiro) {
    //Seta a data atual.
    Date dataAtual = new Date();
    GregorianCalendar calendar = new GregorianCalendar();
    //Define que a semana comea no domingo.
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    //Define a data atual.
    calendar.setTime(dataAtual);//from   ww w . ja  v  a  2 s.co  m
    if (isPrimeiro) {
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    } else {
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    }
    return calendar.getTime();
}

From source file:org.oscarehr.common.hl7.v2.oscar_to_oscar.DataTypeUtils.java

/**
 * This method returns a non-persisted, detached demographic model object.
 * //  w  ww  .  ja v  a 2  s.c  om
 * @throws HL7Exception
 */
public static Demographic parsePid(PID pid) throws HL7Exception {
    Demographic demographic = new Demographic();

    XAD xad = pid.getPatientAddress(0);
    demographic
            .setAddress(StringUtils.trimToNull(xad.getStreetAddress().getStreetOrMailingAddress().getValue()));
    demographic.setCity(StringUtils.trimToNull(xad.getCity().getValue()));
    demographic.setProvince(StringUtils.trimToNull(xad.getStateOrProvince().getValue()));
    demographic.setPostal(StringUtils.trimToNull(xad.getZipOrPostalCode().getValue()));

    GregorianCalendar birthDate = DataTypeUtils.getCalendarFromDTM(pid.getDateTimeOfBirth());
    demographic.setBirthDay(birthDate);

    CX cx = pid.getPatientIdentifierList(0);
    // health card string, excluding version code
    demographic.setHin(StringUtils.trimToNull(cx.getIDNumber().getValue()));
    // blank for everyone but ontario use version code
    demographic.setVer(StringUtils.trimToNull(cx.getIdentifierCheckDigit().getValue()));
    // province
    demographic.setHcType(StringUtils.trimToNull(cx.getAssigningJurisdiction().getIdentifier().getValue()));
    // valid
    GregorianCalendar tempCalendar = DataTypeUtils.getCalendarFromDT(cx.getEffectiveDate());
    if (tempCalendar != null)
        demographic.setEffDate(tempCalendar.getTime());
    // expire
    tempCalendar = DataTypeUtils.getCalendarFromDT(cx.getExpirationDate());
    if (tempCalendar != null)
        demographic.setHcRenewDate(tempCalendar.getTime());

    XPN xpn = pid.getPatientName(0);
    demographic.setLastName(StringUtils.trimToNull(xpn.getFamilyName().getSurname().getValue()));
    demographic.setFirstName(StringUtils.trimToNull(xpn.getGivenName().getValue()));

    XTN phone = pid.getPhoneNumberHome(0);
    demographic.setPhone(StringUtils.trimToNull(phone.getUnformattedTelephoneNumber().getValue()));

    Gender gender = getOscarGenderFromHl7Gender(pid.getAdministrativeSex().getValue());
    if (gender != null)
        demographic.setSex(gender.name());

    return (demographic);
}

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

public static Date convertYYMMDDToDate(int y, int m, int d, boolean beginning_of_day) {
    // if m is out of range, its equiv to 0
    if (m < 0 || m > 11)
        m = 0;/*from  w w w . ja v  a 2  s. c o m*/
    if (d < 0 || d > 30)
        d = 0;
    GregorianCalendar c = new GregorianCalendar();
    c.set(Calendar.YEAR, y);
    c.set(Calendar.MONTH, m);
    c.set(Calendar.DATE, d);
    if (beginning_of_day) {
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
    } else {
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
    }
    return c.getTime();
}

From source file:org.opencms.widgets.CmsCalendarWidget.java

/**
 * Returns the given timestamp as String formatted in a localized pattern.<p>
 * /*from w w  w.  j a  v a  2s. c  o m*/
 * @param locale the locale for the time format
 * @param messages the messages that contain the time format definitions
 * @param timestamp the time to format
 * 
 * @return the given timestamp as String formatted in a localized pattern
 */
public static String getCalendarLocalizedTime(Locale locale, CmsMessages messages, long timestamp) {

    // get the current date & time 
    TimeZone zone = TimeZone.getDefault();
    GregorianCalendar cal = new GregorianCalendar(zone, locale);
    cal.setTimeInMillis(timestamp);
    // format it nicely according to the localized pattern
    DateFormat df = new SimpleDateFormat(CmsCalendarWidget
            .getCalendarJavaDateFormat(messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0)
                    + " " + messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0)));
    return df.format(cal.getTime());
}

From source file:org.mifos.calendar.CalendarUtils.java

public static DateTime getNextDateForMonthOnDate(final DateTime startDate, final int dayOfMonth,
        final int every) {

    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(startDate.toDate());/* w w w.  ja  v a  2  s . co m*/

    gc.add(GregorianCalendar.MONTH, every);
    int M1 = gc.get(GregorianCalendar.MONTH);
    gc.set(GregorianCalendar.DATE, dayOfMonth);
    int M2 = gc.get(GregorianCalendar.MONTH);

    int daynum = dayOfMonth;
    while (M1 != M2) {
        gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1);
        gc.set(GregorianCalendar.DATE, daynum - 1);
        M2 = gc.get(GregorianCalendar.MONTH);
        daynum--;
    }
    return new DateTime(gc.getTime().getTime());
}

From source file:org.nuxeo.ecm.platform.query.nxql.NXQLQueryBuilder.java

public static String getStringValue(DocumentModel model, PredicateFieldDefinition fieldDescriptor) {
    Object rawValue = getRawValue(model, fieldDescriptor);
    if (rawValue == null) {
        return null;
    }/*  w ww  .  j  a  v a2  s . co  m*/
    String value;
    if (rawValue instanceof GregorianCalendar) {
        GregorianCalendar gc = (GregorianCalendar) rawValue;
        value = "TIMESTAMP '" + getDateFormat().format(gc.getTime()) + "'";
    } else if (rawValue instanceof Date) {
        Date date = (Date) rawValue;
        value = "TIMESTAMP '" + getDateFormat().format(date) + "'";
    } else if (rawValue instanceof Integer || rawValue instanceof Long || rawValue instanceof Double) {
        value = rawValue.toString(); // no quotes
    } else if (rawValue instanceof Boolean) {
        value = ((Boolean) rawValue).booleanValue() ? "1" : "0";
    } else {
        value = rawValue.toString().trim();
        if (value.equals("")) {
            return null;
        }
        String fieldType = getFieldType(model, fieldDescriptor);
        if ("long".equals(fieldType) || "integer".equals(fieldType) || "double".equals(fieldType)) {
            return value;
        } else {
            return NXQL.escapeString(value);
        }
    }
    return value;
}

From source file:DateUtility.java

/**
 * This utility returns the last millsecond 
 * of the month, and year, and timezone supplied as arguments.
 *
 * @param int month// w ww. ja  v a 2  s  .c  o m
 * @param int year
 * @param TimeZone tz
 * @return long
 */
static public long getLastMilliOfMonth(int year, int month, TimeZone tz) {
    GregorianCalendar cal = new GregorianCalendar(year, (month - 1), 1);
    cal.setTimeZone(tz);

    // set the maximum last day
    int lastday = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    cal.set(GregorianCalendar.DAY_OF_MONTH, lastday);

    // set other calendar maximums.  - we should do this programatically
    // too but i'm too lazy, and i dont think they're gonna change the gregorian
    // calendar anytime soon.. eh?
    cal.set(GregorianCalendar.HOUR_OF_DAY, 23);
    cal.set(GregorianCalendar.MINUTE, 59);
    cal.set(GregorianCalendar.SECOND, 59);
    cal.set(GregorianCalendar.MILLISECOND, 999);

    long time = cal.getTime().getTime();
    return time;
}

From source file:msec.org.Tools.java

private static XYDataset createDaysDataset(ArrayList<OneDayValue> oneDayValues, GregorianCalendar startgc,
        OneAttrDaysChart chart) {//from w  w w  .j a v a  2  s  .c  om
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    TimeSeries timeseries = new TimeSeries(
            oneDayValues.get(0).getDate() + "-" + oneDayValues.get(oneDayValues.size() - 1).getDate());
    int sum = 0;
    int max = 0;
    int min = 0;
    Minute current = new Minute(startgc.getTime());
    for (int j = 0; j < oneDayValues.size(); j++) {
        int[] data = oneDayValues.get(j).getValues();
        //check actual length for data
        int len = data.length - 1;
        if (j == oneDayValues.size() - 1) {
            //if last day is today...
            if (oneDayValues.get(j).getDate().equals(Tools.nowString("yyyyMMdd"))) {
                for (int i = len; i >= 0; i--) {
                    if (data[i] != 0) {
                        len = i;
                        break;
                    }
                }
            }
        }
        for (int i = 0; i < len; ++i) {
            timeseries.add(current, (double) (data[i]));
            sum += data[i];
            max = Math.max(max, data[i]);
            if (min == 0)
                min = data[i];
            else if (data[i] != 0)
                min = Math.min(min, data[i]);
            current = (Minute) current.next();
        }
    }
    chart.setMax(max);
    chart.setMin(min);
    chart.setSum(sum);
    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}

From source file:org.nuclos.common2.SeriesUtils.java

/**
 * /*from   w  ww .ja  va 2  s .c o  m*/
 * @param dateFrom
 * @param dateUntil
 * @return
 */
public static List<DateTime> getPossibleDates(String series, DateTime dateFrom, DateTime dateUntil) {
    List<DateTime> result = new ArrayList<DateTime>();

    if (dateUntil.before(dateFrom)) {
        return result;
    }

    final GregorianCalendar calendar = new GregorianCalendar();

    DateTime dateCalculated = getSeriesNext(series, dateFrom);
    while (dateCalculated.before(dateUntil)) {
        result.add(dateCalculated);

        calendar.setTime(dateCalculated.getDate());
        calendar.add(GregorianCalendar.MINUTE, 1);
        dateCalculated = getSeriesNext(series, new DateTime(calendar.getTime()));
    }

    return result;
}