Example usage for java.util Calendar DST_OFFSET

List of usage examples for java.util Calendar DST_OFFSET

Introduction

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

Prototype

int DST_OFFSET

To view the source code for java.util Calendar DST_OFFSET.

Click Source Link

Document

Field number for get and set indicating the daylight saving offset in milliseconds.

Usage

From source file:org.openmeetings.app.remote.InvitationService.java

/**
 * send an invitation to another user by Mail
 * /*www.  j a va2s.  c  o m*/
 * @param SID
 * @param username
 * @param message
 * @param baseurl
 * @param email
 * @param subject
 * @param room_id
 * @param conferencedomain
 * @param isPasswordProtected
 * @param invitationpass
 * @param valid
 * @param validFromDate
 * @param validFromTime
 * @param validToDate
 * @param validToTime
 * @param language_id
  * @param jNameTimeZone
 * @return
 */
public String sendInvitationHash(String SID, String username, String message, String baseurl, String email,
        String subject, Long room_id, String conferencedomain, Boolean isPasswordProtected,
        String invitationpass, Integer valid, Date validFromDate, String validFromTime, Date validToDate,
        String validToTime, Long language_id, String jNameTimeZone) {

    try {
        log.debug("sendInvitationHash: ");

        Integer validFromHour = Integer.valueOf(validFromTime.substring(0, 2)).intValue();
        Integer validFromMinute = Integer.valueOf(validFromTime.substring(3, 5)).intValue();

        Integer validToHour = Integer.valueOf(validToTime.substring(0, 2)).intValue();
        Integer validToMinute = Integer.valueOf(validToTime.substring(3, 5)).intValue();

        log.info("validFromHour: " + validFromHour);
        log.info("validFromMinute: " + validFromMinute);

        Calendar calFrom = Calendar.getInstance();
        calFrom.setTime(validFromDate);
        calFrom.set(Calendar.HOUR_OF_DAY, validFromHour);
        calFrom.set(Calendar.MINUTE, validFromMinute);
        calFrom.set(Calendar.SECOND, 0);

        Calendar calTo = Calendar.getInstance();
        calTo.setTime(validToDate);
        calTo.set(Calendar.HOUR_OF_DAY, validToHour);
        calTo.set(Calendar.MINUTE, validToMinute);
        calTo.set(Calendar.SECOND, 0);

        Date dFrom = calFrom.getTime();
        Date dTo = calTo.getTime();

        Long users_id = sessionManagement.checkSession(SID);
        Long user_level = userManagement.getUserLevelByID(users_id);

        OmTimeZone omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone);

        // If everything fails
        if (omTimeZone == null) {
            Configuration conf = cfgManagement.getConfKey(3L, "default.timezone");
            if (conf != null) {
                jNameTimeZone = conf.getConf_value();
            }
            omTimeZone = omTimeZoneDaoImpl.getOmTimeZone(jNameTimeZone);
        }

        String timeZoneName = omTimeZone.getIcal();

        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone(timeZoneName));
        int offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);

        log.debug("addAppointment offset :: " + offset);

        Date gmtTimeStart = new Date(dFrom.getTime() - offset);
        Date gmtTimeEnd = new Date(dTo.getTime() - offset);

        Invitations invitation = invitationManagement.addInvitationLink(user_level, username, message, baseurl,
                email, subject, room_id, conferencedomain, isPasswordProtected, invitationpass, valid, dFrom,
                dTo, users_id, baseurl, language_id, true, gmtTimeStart, gmtTimeEnd, null, username);

        if (invitation != null) {
            return "success";
        } else {
            return "Sys - Error";
        }
    } catch (Exception err) {
        log.error("[sendInvitationHash]", err);
    }

    return null;

    // return
    // invitationManagement.sendInvitionLink(user_level,
    // username, message, domain, room, roomtype, baseurl, email, subject,
    // room_id);
}

From source file:ISO8601DateTimeFormat.java

/**
 * Write the time zone string.//  ww w . ja va  2  s  .  c  o  m
 * @param sbuf The buffer to append the time zone.
 */
protected final void writeTZ(StringBuffer sbuf) {
    int offset = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET);
    if (offset == 0) {
        sbuf.append('Z');
    } else {
        int offsetHour = offset / 3600000;
        int offsetMin = (offset % 3600000) / 60000;
        if (offset >= 0) {
            sbuf.append('+');
        } else {
            sbuf.append('-');
            offsetHour = 0 - offsetHour;
            offsetMin = 0 - offsetMin;
        }
        appendInt(sbuf, offsetHour, 2);
        sbuf.append(':');
        appendInt(sbuf, offsetMin, 2);
    }
}

From source file:org.openbravo.client.kernel.reference.TimeUIDefinition.java

private StringBuffer convertLocalTimeToUTC(String value) {
    StringBuffer localTimeColumnValue = null;
    try {//from  w  w w. j ava  2 s  .c  o  m
        Date UTCDate = getClassicFormat().parse(value);
        Calendar now = Calendar.getInstance();

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(UTCDate);
        calendar.set(Calendar.DATE, now.get(Calendar.DATE));
        calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
        calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));

        int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET));
        calendar.add(Calendar.MILLISECOND, -gmtMillisecondOffset);
        localTimeColumnValue = getClassicFormat().format(calendar.getTime(), new StringBuffer(),
                new FieldPosition(0));
    } catch (ParseException e) {
        throw new OBException("Exception when parsing date ", e);
    }
    return localTimeColumnValue;
}

From source file:com.taobao.itest.util.DateConverter.java

/**
 * get GMT Time/*  w  w  w  .  jav a 2  s  .  co  m*/
 * 
 * @param calendar
 * @return
 */
public Date getGmtDate(Long time) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time);
    int offset = calendar.get(Calendar.ZONE_OFFSET) / 3600000 + calendar.get(Calendar.DST_OFFSET) / 3600000;
    calendar.add(Calendar.HOUR, -offset);
    Date date = calendar.getTime();

    return date;
}

From source file:com.krawler.common.timezone.Timezone.java

public static Date getGmtDate() throws ServiceException {
    Date cmpdate = new Date();
    try {/*  ww  w .j a  v  a 2  s. c o  m*/
        Calendar calInstance = Calendar.getInstance();
        int gmtoffset = calInstance.get(Calendar.DST_OFFSET) + calInstance.get(Calendar.ZONE_OFFSET);
        long date = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy HH:mm a");
        String cmp = sdf.format(new java.util.Date(date));
        cmpdate = new Date(sdf.parse(cmp).getTime() - gmtoffset);
    } catch (ParseException e) {
        throw ServiceException.FAILURE("Timezone.getGmtDate", e);
    }
    return cmpdate;
}

From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java

/**
 * This method is used to get Calendar date for the corresponding date object.
 *
 * @param date(Date) date for which Calendar value has to be found.
 * @return calendar value corresponding to the date.
 *///from  w  w w.j  a va 2s.com
@Override
public Calendar convertDateToCalendar(java.util.Date date) {
    Calendar calendar = null;
    if (date != null) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.clear(Calendar.ZONE_OFFSET);
        calendar.clear(Calendar.DST_OFFSET);
    }
    return calendar;
}

From source file:org.openmeetings.utils.math.TimezoneUtil.java

public static long _getOffset(TimeZone timezone) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(timezone);//from  w w w .  j  a va  2 s .c  o m
    return cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
}

From source file:org.exoplatform.webui.utils.TimeConvertUtils.java

/**
 * Get current time GMT/Zulu or UTC,(zone time is 0+GMT)
 * @return Calendar /*from   w  w  w .  jav  a 2 s. c  o  m*/
 */
public static Calendar getGreenwichMeanTime() {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setLenient(false);
    int gmtoffset = calendar.get(Calendar.DST_OFFSET) + calendar.get(Calendar.ZONE_OFFSET);
    calendar.setTimeInMillis(System.currentTimeMillis() - gmtoffset);
    return calendar;
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

public static void appendTimeZone(Calendar calendar, StringBuffer dateString) {
    int timezoneOffSet = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET);
    int timezoneOffSetInMinits = timezoneOffSet / 60000;
    if (timezoneOffSetInMinits < 0) {
        dateString.append("-");
        timezoneOffSetInMinits = timezoneOffSetInMinits * -1;
    } else {/*  www . jav a  2  s .  co m*/
        dateString.append("+");
    }
    int hours = timezoneOffSetInMinits / 60;
    int minits = timezoneOffSetInMinits % 60;

    if (hours < 10) {
        dateString.append("0");
    }
    dateString.append(hours).append(":");

    if (minits < 10) {
        dateString.append("0");
    }

    dateString.append(minits);
}

From source file:org.energy_home.jemma.internal.ah.eh.esp.ESPContainersDataUtils.java

public static int getResultListSize(Calendar c, long normalizedStartTime, long normalizedEndTime,
        int resolution) {
    int result = 0;
    long additionalHours = 0;
    int startDst, endDst;

    switch (resolution) {
    case ESPService.MONTH_RESOLUTION:
        c.setTimeInMillis(normalizedStartTime);
        int startYear = c.get(Calendar.YEAR);
        int startMonth = c.get(Calendar.MONTH);
        c.setTimeInMillis(normalizedEndTime);
        int endYear = c.get(Calendar.YEAR);
        int endMonth = c.get(Calendar.MONTH);
        if (startYear == endYear) {
            result = endMonth - startMonth + 1;
        } else if (endYear > startYear) {
            result = (endYear - startYear - 1) * 12 + (12 - startMonth) + endMonth + 1;
        } else//from  w w  w . j ava  2s  .  c  o  m
            result = 0;
        break;
    case ESPService.DAY_RESOLUTION:
        c.setTimeInMillis(normalizedStartTime);
        startDst = c.get(Calendar.DST_OFFSET);
        c.setTimeInMillis(normalizedEndTime);
        endDst = c.get(Calendar.DST_OFFSET);
        additionalHours = endDst - startDst;
        if (additionalHours != 0)
            log.info("Legal/solar switch error correction: " + additionalHours);
        result = (int) ((normalizedEndTime - normalizedStartTime + additionalHours)
                / DateUtils.MILLISEC_IN_ONE_DAY) + 1;
        break;
    case ESPService.HOUR_RESOLUTION:
        c.setTimeInMillis(normalizedStartTime);
        startDst = c.get(Calendar.DST_OFFSET);
        c.setTimeInMillis(normalizedEndTime);
        endDst = c.get(Calendar.DST_OFFSET);
        additionalHours = endDst - startDst;
        if (additionalHours != 0)
            log.info("Legal/solar switch error correction: " + additionalHours);
        result = (int) ((normalizedEndTime - normalizedStartTime + additionalHours)
                / DateUtils.MILLISEC_IN_ONE_HOUR) + 1;
        break;
    }
    if (result < 0)
        result = 0;
    if (result > 50)
        log.warn(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> getResultListSize return more than 50 results");
    return result;
}