Example usage for java.util TimeZone getTimeZone

List of usage examples for java.util TimeZone getTimeZone

Introduction

In this page you can find the example usage for java.util TimeZone getTimeZone.

Prototype

public static TimeZone getTimeZone(ZoneId zoneId) 

Source Link

Document

Gets the TimeZone for the given zoneId .

Usage

From source file:org.dasein.security.joyent.SignatureHttpAuth.java

@Override
public void addPreemptiveAuth(@Nonnull HttpRequest request) throws CloudException, InternalException {
    if (provider.getContext() == null) {
        throw new CloudException("No context was defined for this request");
    }/*from w  w w  .  j  a  v  a  2 s  .  co  m*/
    Date date = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
    String now = RFC1123_DATE_FORMAT.format(date);
    request.setHeader("Date", now);
    try {
        Security.addProvider(new BouncyCastleProvider());
        Signature signature = Signature.getInstance(SIGN_ALGORITHM);

        List<ContextRequirements.Field> fields = provider.getContextRequirements().getConfigurableValues();
        String keyName = "";
        String privateKey = "";
        char[] keyPassword = null;
        for (ContextRequirements.Field f : fields) {
            if (f.type.equals(ContextRequirements.FieldType.KEYPAIR)) {
                byte[][] keyPair = (byte[][]) provider.getContext().getConfigurationValue(f);
                keyName = new String(keyPair[0], "utf-8");
                privateKey = new String(keyPair[1], "utf-8");
            } else if (f.type.equals(ContextRequirements.FieldType.PASSWORD)) {
                byte[] password = (byte[]) provider.getContext().getConfigurationValue(f);
                if (password != null) {
                    keyPassword = new String(password, "utf-8").toCharArray();
                }
            }
        }

        signature.initSign(getKeyPair(privateKey, keyPassword).getPrivate());
        String signingString = String.format(AUTH_SIGN, now);
        signature.update(signingString.getBytes("UTF-8"));
        byte[] signedDate = signature.sign();
        byte[] encodedSignedDate = Base64.encode(signedDate);

        request.addHeader("Authorization", String.format(AUTH_HEADER, provider.getContext().getAccountNumber(),
                keyName, new String(encodedSignedDate)));

    } catch (NoSuchAlgorithmException e) {
        throw new InternalException(e);
    } catch (UnsupportedEncodingException e) {
        throw new InternalException(e);
    } catch (SignatureException e) {
        throw new InternalException(e);
    } catch (InvalidKeyException e) {
        throw new InternalException(e);
    } catch (IOException e) {
        throw new InternalException(e);
    }
}

From source file:ch.zhaw.icclab.tnova.expressionsolver.KPI.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from w w  w.  ja  va  2 s .c o m
public String showKPI() {
    KPI.api_calls += 1; //tracking the current call
    JSONObject obj = new JSONObject();
    obj.put("src", "t-nova expression evaluation service");
    obj.put("msg", "kpi parameters data");

    obj.put("api-calls-total", api_calls);
    obj.put("api-calls-failed", api_calls_failed);
    obj.put("expressions-evaluated", expressions_evaluated);
    obj.put("expressions-under-evaluation", expressions_under_evaluation);
    Date date = new Date(lastknownunixtime);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+1"));
    String formattedDate = sdf.format(date);
    obj.put("data-since", formattedDate);

    KPI.api_calls_success += 1;
    obj.put("api-calls-success", api_calls_success);
    //lastknownunixtime = System.currentTimeMillis();
    initialize();
    logger.info("URI:/kpi Method:GET Request procesed. The KPI parameters have been reset.");
    return obj.toJSONString();
}

From source file:fxts.stations.trader.ui.dialogs.ADatePage.java

/**
 * Returns begining date//w  w  w  .j a  va  2 s.  com
 *
 * @return
 */
public String getBeginDate() {
    Calendar instance = Calendar.getInstance();
    instance.setTime(mCalendarComboBegin.getDate());
    boolean date = instance.get(Calendar.DATE) == Calendar.getInstance().get(Calendar.DATE);
    boolean month = instance.get(Calendar.MONTH) == Calendar.getInstance().get(Calendar.MONTH);
    boolean year = instance.get(Calendar.YEAR) == Calendar.getInstance().get(Calendar.YEAR);
    if (date && month && year) {
        TradingSessionStatus tss = TradingServerSession.getInstance().getTradingSessionStatus();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone(tss.getFXCMServerTimeZoneName()));
        String etd = TradingServerSession.getInstance().getParameterValue("END_TRADING_DAY");
        String now = sdf.format(new Date());
        if (now.compareTo(etd) > 0) {
            instance.roll(Calendar.DATE, true);
        }
        return mDateFormat.format(instance.getTime());
    } else {
        return mDateFormat.format(mCalendarComboBegin.getDate());
    }
}

From source file:com.hybris.datahub.core.util.OutboundServiceCsvUtilsUnitTest.java

@Test
public void testGetStringValueOfObject_StringValueOfUtcDateCanBeConvertedBackToOriginalDate()
        throws ParseException {
    final Date originalDate = new Date();
    final String formattedDate = csvUtils.getStringValueOfObject(originalDate);

    final SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    final Date convertedDate = formatter.parse(formattedDate);

    Assert.assertTrue(originalDate.getTime() == convertedDate.getTime());
    Assert.assertEquals(0, originalDate.compareTo(convertedDate));
}

From source file:GmtCalendar.java

/**
 * Constructs a GregorianCalendar with the given date and time set for the
 * GMT time zone with the default locale.
 * //from ww w . j ava2  s  .c  om
 * @param year
 *            the value used to set the YEAR time field in the calendar.
 * @param month
 *            the value used to set the MONTH time field in the calendar.
 *            Month value is 0-based. e.g., 0 for January.
 * @param date
 *            the value used to set the DATE time field in the calendar.
 * @param hour
 *            the value used to set the HOUR_OF_DAY time field in the
 *            calendar.
 * @param minute
 *            the value used to set the MINUTE time field in the calendar.
 */

public GmtCalendar(int year, int month, int date, int hour, int minute) {

    super(TimeZone.getTimeZone("GMT"), Locale.getDefault());

    this.set(ERA, AD);

    this.set(YEAR, year);

    this.set(MONTH, month);

    this.set(DATE, date);

    this.set(HOUR_OF_DAY, hour);

    this.set(MINUTE, minute);

}

From source file:com.redhat.rhevm.api.powershell.util.PowerShellUtils.java

public static XMLGregorianCalendar getDate(int secondsAgo) {
    if (secondsAgo == 0) {
        return null;
    }//from w w w .  ja  v a  2s.com
    XMLGregorianCalendar ret = getDatatypeFactory()
            .newXMLGregorianCalendar(new GregorianCalendar(TimeZone.getTimeZone("UTC")));
    ret.add(getDatatypeFactory().newDuration(false, 0, 0, 0, 0, 0, secondsAgo));
    return ret;
}

From source file:org.sbq.batch.mains.SchedulerRunner.java

private void scheduleCalculateEvent() throws SchedulerException {
    JobDetail job = newJob(CalculateEventMetricsScheduledJob.class)
            .withIdentity("calculateEventMetricsScheduledJob", "MetricsCollectors").requestRecovery(false)
            .build();//from  www. j a  v a2  s . c  o m
    CronTrigger trigger = newTrigger()
            .withIdentity("triggerFor_calculateEventMetricsScheduledJob", "MetricsCollectors")
            .withSchedule(cronSchedule("0 0/5 * * * ?").inTimeZone(TimeZone.getTimeZone("UTC"))
                    .withMisfireHandlingInstructionFireAndProceed())
            .forJob(job.getKey()).build();
    trigger.getJobDataMap().putAsString("finishedAt", System.currentTimeMillis());
    scheduleJobWithTriggerIfNotPresent(job, trigger);
}

From source file:com.collabnet.ccf.core.utils.DateUtil.java

public static Date convertToGMTAbsoluteDate(Date dateValue, String sourceSystemTimezone) {
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(sourceSystemTimezone));
    cal.setLenient(false);/*from  w  w w  .  j  ava 2  s. c om*/
    cal.setTime(dateValue);
    Calendar newCal = new GregorianCalendar(TimeZone.getTimeZone(GMT_TIME_ZONE_STRING));
    newCal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    newCal.set(Calendar.MILLISECOND, 0);
    Date returnDate = newCal.getTime();
    return returnDate;
}

From source file:com.auditbucket.engine.repo.neo4j.model.TrackLogRelationship.java

public TrackLogRelationship(MetaHeader header, ChangeLog log, DateTime fortressWhen) {
    this();//  w  w w.ja v a  2  s  . c o  m
    this.metaHeader = (MetaHeaderNode) header;
    this.changeLog = (ChangeLogNode) log;
    if (fortressWhen != null && fortressWhen.getMillis() != 0) {
        this.fortressWhen = fortressWhen.getMillis();
    } else {
        // "now" in the fortress default timezone
        this.fortressWhen = new DateTime(sysWhen,
                DateTimeZone.forTimeZone(TimeZone.getTimeZone(header.getFortress().getTimeZone()))).getMillis();
    }
}

From source file:org.onebusaway.webapp.actions.where.BlockAction.java

@Override
@Actions({ @Action(value = "/where/standard/block"), @Action(value = "/where/iphone/block"),
        @Action(value = "/where/text/block") })
public String execute() throws ServiceException {

    if (_id == null)
        return INPUT;

    _blockInstance = _service.getBlockInstance(_id, _serviceDate.getTime());

    if (_blockInstance == null)
        return ERROR;

    BlockConfigurationBean blockConfig = _blockInstance.getBlockConfiguration();
    _timeZone = TimeZone.getTimeZone(blockConfig.getTimeZone());

    return SUCCESS;
}