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.opencastproject.capture.impl.ConfigurationManager.java

private void updateTimezone(XProperties properties) {
    Calendar cal = Calendar.getInstance();
    properties.setProperty("capture.device.timezone.offset",
            Long.toString((cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET))
                    / (1 * CaptureParameters.MINUTES * CaptureParameters.MILLISECONDS)));
    properties.setProperty("capture.device.timezone", TimeZone.getDefault().getID());
}

From source file:foam.uavtoolkit.starwisp.java

/** Called when the activity is first created. */
@Override//ww  w  .j a va2 s .  c  o m
public void onCreate(Bundle savedInstanceState) {
    String dirname = "uavtoolkit/";
    m_AppDir = "/sdcard/" + dirname;
    File appdir = new File(m_AppDir);
    appdir.mkdirs();

    File filesdir = new File(m_AppDir + "/files/");
    filesdir.mkdirs();
    File backupdir = new File(m_AppDir + "/backup/");
    backupdir.mkdirs();

    // build static things
    m_Scheme = new Scheme(this);

    m_Scheme.Load("lib.scm");
    m_Scheme.Load("json.scm");
    m_Scheme.Load("racket-fix.scm");
    m_Scheme.Load("eavdb/ktv.ss");
    m_Scheme.Load("eavdb/ktv-list.ss");
    m_Scheme.Load("eavdb/entity-values.ss");
    m_Scheme.Load("eavdb/entity-insert.ss");
    m_Scheme.Load("eavdb/entity-get.ss");
    m_Scheme.Load("eavdb/entity-update.ss");
    m_Scheme.Load("eavdb/entity-filter.ss");
    m_Scheme.Load("eavdb/entity-sync.ss");
    m_Scheme.Load("eavdb/entity-csv.ss");
    m_Scheme.Load("eavdb/eavdb.ss");
    m_Scheme.Load("dbsync.scm");

    m_Builder = new StarwispBuilder(m_Scheme);
    m_Name = "main";

    // tell scheme the date
    final Calendar c = Calendar.getInstance();
    int day = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH) + 1;
    int year = c.get(Calendar.YEAR);
    int timezone_offset_mins = (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)) / 60000;

    String version = "Version not found";
    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        version = pInfo.versionName;
    } catch (NameNotFoundException e) {
        Log.e("starwisp", "Error getting version " + e.toString());
    }

    // pass in a bunch of useful stuff
    m_Scheme.eval("(define dirname \"/sdcard/" + dirname + "\")" + "(define date-day " + day + ")"
            + "(define date-month " + month + ")" + "(define date-year " + year + ")"
            + "(define timezone-offset-mins " + timezone_offset_mins + ")" + "(define app-version " + version
            + ")");

    // pass in a bunch of useful stuff
    DeclareSensors();

    m_Scheme.Load("review-data.scm");
    m_Scheme.Load("uav-toolkit.scm");

    Log.i("starwisp", "started, now running starwisp.scm...");
    m_Scheme.eval(m_Scheme.readRawTextFile(this, "translations.scm"));
    m_Scheme.eval(m_Scheme.readRawTextFile(this, "starwisp.scm"));

    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

}

From source file:net.maritimecloud.identityregistry.controllers.BaseControllerWithCertificate.java

protected PemCertificate issueCertificate(CertificateModel certOwner, Organization org, String type,
        HttpServletRequest request) throws McBasicRestException {
    // Generate keypair for user
    KeyPair userKeyPair = CertificateUtil.generateKeyPair();
    // Find special MC attributes to put in the certificate
    HashMap<String, String> attrs = getAttr(certOwner);

    String o = org.getMrn();/*  w  w w  . j av a  2s.c  o m*/
    String name = getName(certOwner);
    String email = getEmail(certOwner);
    String uid = getUid(certOwner);
    if (uid == null || uid.trim().isEmpty()) {
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.ENTITY_ORG_ID_MISSING,
                request.getServletPath());
    }
    BigInteger serialNumber = certUtil.generateSerialNumber();
    X509Certificate userCert = certUtil.generateCertForEntity(serialNumber, org.getCountry(), o, type, name,
            email, uid, userKeyPair.getPublic(), attrs);
    String pemCertificate;
    try {
        pemCertificate = CertificateUtil.getPemFromEncoded("CERTIFICATE", userCert.getEncoded()).replace("\n",
                "\\n");
    } catch (CertificateEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    String pemPublicKey = CertificateUtil.getPemFromEncoded("PUBLIC KEY", userKeyPair.getPublic().getEncoded())
            .replace("\n", "\\n");
    String pemPrivateKey = CertificateUtil
            .getPemFromEncoded("PRIVATE KEY", userKeyPair.getPrivate().getEncoded()).replace("\n", "\\n");
    PemCertificate ret = new PemCertificate(pemPrivateKey, pemPublicKey, pemCertificate);

    // Create the certificate
    Certificate newMCCert = new Certificate();
    certOwner.assignToCert(newMCCert);
    newMCCert.setCertificate(pemCertificate);
    newMCCert.setSerialNumber(serialNumber);
    // The dates we extract from the cert is in localtime, so they are converted to UTC before saving into the DB
    Calendar cal = Calendar.getInstance();
    long offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
    newMCCert.setStart(new Date(userCert.getNotBefore().getTime() - offset));
    newMCCert.setEnd(new Date(userCert.getNotAfter().getTime() - offset));
    this.certificateService.saveCertificate(newMCCert);
    return ret;
}

From source file:edu.harvard.i2b2.query.data.QueryConceptTreePanelData.java

public ConstrainByDate writeTimeConstraint() {
    ConstrainByDate timeConstrain = new ConstrainByDate();
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    log.info("Timezone: " + tz.getID() + " : " + zt_offset);

    if (startTime() != -1) {
        ConstrainDateType constraindateType = new ConstrainDateType();
        XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(startYear(), startMonth() + 1,
                startDay());/* ww  w . j ava 2  s  .  c  o  m*/
        xmlC.setTimezone(zt_offset);//0);//-5*60);
        xmlC.setHour(0);
        xmlC.setMinute(0);
        xmlC.setSecond(0);
        constraindateType.setValue(xmlC);
        timeConstrain.setDateFrom(constraindateType);
    }

    if (endTime() != -1) {
        ConstrainDateType constraindateType = new ConstrainDateType();
        XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(endYear(), endMonth() + 1, endDay());
        xmlC.setTimezone(zt_offset);//0);//-5*60);
        xmlC.setHour(0);
        xmlC.setMinute(0);
        xmlC.setSecond(0);
        constraindateType.setValue(xmlC);
        timeConstrain.setDateTo(constraindateType);
    }
    return timeConstrain;
}

From source file:org.openhab.binding.astro.internal.common.AstroConfig.java

@Override
public String toString() {
    String intervallMessage = (interval == 0 ? "disabled" : String.valueOf(interval));

    TimeZone tz = TimeZone.getDefault();
    StringBuilder tzInfo = new StringBuilder();
    tzInfo.append(tz.getID());/*w ww. j ava  2s  . c  om*/
    tzInfo.append(" (").append(tz.getDisplayName(false, TimeZone.SHORT)).append(" ")
            .append(new SimpleDateFormat("Z").format(Calendar.getInstance().getTime()));
    tzInfo.append(")");
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("latitude", latitude)
            .append("longitude", longitude).append("interval", intervallMessage)
            .append("systemTimezone", tzInfo.toString())
            .append("daylightSavings", Calendar.getInstance().get(Calendar.DST_OFFSET) != 0).toString();
}

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

private StringBuffer convertUtcToLocalTime(String value) {
    StringBuffer localTimeColumnValue = null;
    try {/*  w w w  . j a  v a  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:ISO8601DateTimeFormat.java

/**
 * Parse the time zone.// w  w  w .ja  v  a  2s .  c  om
 * @param i The position to start parsing.
 * @param text The text to parse.
 * @return The position after parsing has finished.
 */
protected final int parseTZ(int i, String text) {
    if (i < text.length()) {
        // check and handle the zone/dst offset
        int offset = 0;
        if (text.charAt(i) == 'Z') {
            offset = 0;
            i++;
        } else {
            int sign = 1;
            if (text.charAt(i) == '-') {
                sign = -1;
            } else if (text.charAt(i) != '+') {
                throw new NumberFormatException();
            }
            i++;

            int offsetHour = Integer.valueOf(text.substring(i, i + 2)).intValue();
            i += 2;

            if (text.charAt(i) != ':') {
                throw new NumberFormatException();
            }
            i++;

            int offsetMin = Integer.valueOf(text.substring(i, i + 2)).intValue();
            i += 2;
            offset = ((offsetHour * 60) + offsetMin) * 60000 * sign;
        }
        int offsetCal = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET);

        calendar.add(Calendar.MILLISECOND, offsetCal - offset);
    }
    return i;
}

From source file:org.hyperic.snmp.SNMPValue.java

private long convertDateAndTimeToLong() throws SNMPException {
    byte[] bytes = getBytes();

    if (bytes.length < 8) {
        String msg = "OctetString is not in DateAndTime syntax";

        throw new SNMPException(msg);
    }/*from  w  ww  .j  a v  a 2  s.  c o m*/

    Calendar cal = Calendar.getInstance();

    int ix = 0;

    int year = (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]);

    year <<= 8;

    ix++;

    year += (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]);

    ix++;

    int month = bytes[ix++];
    int day = bytes[ix++];
    int hour = bytes[ix++];
    int minutes = bytes[ix++];
    int seconds = bytes[ix++];
    int deciseconds = bytes[ix++];

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, (month - 1));
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minutes);
    cal.set(Calendar.SECOND, seconds);
    cal.set(Calendar.MILLISECOND, (100 * deciseconds));
    cal.set(Calendar.ZONE_OFFSET, 0);
    cal.set(Calendar.DST_OFFSET, 0);

    if (log.isDebugEnabled()) {
        log.debug("converted to DateAndTime: millis=" + cal.getTimeInMillis() + ", date=" + cal.getTime());
    }

    return cal.getTimeInMillis();
}

From source file:org.rhq.plugins.www.snmp.SNMPValue.java

private long convertDateTimeOctetStringToLong() throws SNMPException {
    byte[] bytes = ((OctetString) this.var).getValue();

    if (bytes.length != 8) {
        throw new SNMPException("OctetString is not in DateAndTime syntax.");
    }//  w  ww . ja  v a2  s.  com

    Calendar cal = Calendar.getInstance();

    int ix = 0;
    int year = (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]);

    year <<= 8;
    ix++;
    year += (bytes[ix] > 0) ? bytes[ix] : (256 + bytes[ix]);

    ix++;

    int month = bytes[ix++];
    int day = bytes[ix++];
    int hour = bytes[ix++];
    int minutes = bytes[ix++];
    int seconds = bytes[ix++];
    int deciseconds = bytes[ix++];

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, (month - 1));
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minutes);
    cal.set(Calendar.SECOND, seconds);
    cal.set(Calendar.MILLISECOND, (100 * deciseconds));
    cal.set(Calendar.ZONE_OFFSET, 0);
    cal.set(Calendar.DST_OFFSET, 0);

    if (log.isDebugEnabled()) {
        log.debug("converted to DateAndTime: millis=" + cal.getTimeInMillis() + ", date=" + cal.getTime());
    }

    return cal.getTimeInMillis();
}

From source file:ch.ethz.dcg.jukefox.model.player.playlog.PlayLog.java

License:asdf

public void writeToPlayLog(final Date time, final PlaylistSong<BaseArtist, BaseAlbum> song, final boolean skip,
        final int playbackPosition) {
    int day_of_week = 0, hour_of_day = 0;
    long utcTime = time.getTime();

    Calendar cal = Calendar.getInstance();

    // in minutes
    int timeZoneOffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    // in hours// www .  j  ava2s .  c  o m
    timeZoneOffset /= 60;

    Calendar logcalendar = Calendar.getInstance();
    logcalendar.setTimeInMillis(time.getTime());
    day_of_week = logcalendar.get(Calendar.DAY_OF_WEEK);
    hour_of_day = logcalendar.get(Calendar.HOUR_OF_DAY);
    Log.v(TAG, "day of week: " + day_of_week);
    Log.v(TAG, "hour of day: " + hour_of_day);
    Log.v(TAG, "utcTime: " + utcTime);

    AbstractContextResult contextData = contextProvider.getMeanContextValues(30 * 1000);

    try {
        // Write playlog entry
        dbDataPortal.writePlayLogEntry(playerModelId, song, utcTime, timeZoneOffset, day_of_week, hour_of_day,
                skip, playerController.getPlayMode().getPlayModeType().value(), contextData, playbackPosition);

        // Write a rating entry as well
        double fractionPlayed = playbackPosition / (double) song.getDuration();
        ratingHelper.addRatingFromPlayLog(song, time, fractionPlayed);
    } catch (DataWriteException e) {
        Log.w(TAG, e);
    }
}