Example usage for org.joda.time DateTimeZone forTimeZone

List of usage examples for org.joda.time DateTimeZone forTimeZone

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone forTimeZone.

Prototype

public static DateTimeZone forTimeZone(TimeZone zone) 

Source Link

Document

Gets a time zone instance for a JDK TimeZone.

Usage

From source file:org.springframework.batch.admin.domain.JobExecutionInfoResource.java

License:Apache License

public JobExecutionInfoResource(JobExecution jobExecution, TimeZone timeZone) {

    if (timeZone != null) {
        this.timeZone = timeZone;
    } else {//w w  w . j  av a 2s . c  o  m
        this.timeZone = TimeZone.getTimeZone("UTC");
    }

    this.executionId = jobExecution.getId();
    this.jobId = jobExecution.getJobId();
    this.stepExecutionCount = jobExecution.getStepExecutions().size();
    this.jobParameters = jobExecution.getJobParameters();
    this.status = jobExecution.getStatus();
    this.exitStatus = jobExecution.getExitStatus();
    this.jobConfigurationName = jobExecution.getJobConfigurationName();
    this.failureExceptions = jobExecution.getFailureExceptions();
    Map<String, Object> executionContextEntires = new HashMap<String, Object>(
            jobExecution.getExecutionContext().size());

    for (Map.Entry<String, Object> stringObjectEntry : jobExecution.getExecutionContext().entrySet()) {
        executionContextEntires.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
    }

    this.executionContext = executionContextEntires;

    this.version = jobExecution.getVersion();

    JobInstance jobInstance = jobExecution.getJobInstance();
    if (jobInstance != null) {
        this.jobName = jobInstance.getJobName();
        BatchStatus status = jobExecution.getStatus();
        this.restartable = status.isGreaterThan(BatchStatus.STOPPING)
                && status.isLessThan(BatchStatus.ABANDONED);
        this.abandonable = status.isGreaterThan(BatchStatus.STARTED) && status != BatchStatus.ABANDONED;
        this.stoppable = status.isLessThan(BatchStatus.STOPPING) && status != BatchStatus.COMPLETED;
    } else {
        this.jobName = "?";
    }

    this.dateFormat = this.dateFormat.withZone(DateTimeZone.forTimeZone(timeZone));

    this.createDate = dateFormat.print(jobExecution.getCreateTime().getTime());
    this.lastUpdated = dateFormat.print(jobExecution.getLastUpdated().getTime());

    if (jobExecution.getStartTime() != null) {
        this.startTime = dateFormat.print(jobExecution.getStartTime().getTime());

        if (!jobExecution.isRunning()) {
            this.endTime = dateFormat.print(jobExecution.getEndTime().getTime());
        } else {
            this.endTime = "N/A";
        }
    }
}

From source file:org.springframework.batch.admin.domain.StepExecutionInfoResource.java

License:Apache License

/**
 * @param stepExecution Must not be null
 * @param timeZone timeZone dates are represented in.
 *///from   w w  w.java2s.  co  m
public StepExecutionInfoResource(StepExecution stepExecution, TimeZone timeZone) {
    Assert.notNull(stepExecution, "stepExecution must not be null.");

    if (timeZone != null) {
        this.timeZone = timeZone;
    } else {
        this.timeZone = TimeZone.getTimeZone("UTC");
    }

    this.dateFormat = this.dateFormat.withZone(DateTimeZone.forTimeZone(this.timeZone));

    this.jobExecutionId = stepExecution.getJobExecutionId();
    if (stepExecution.getExecutionContext().containsKey(Step.STEP_TYPE_KEY)) {
        this.stepType = (String) stepExecution.getExecutionContext().get(Step.STEP_TYPE_KEY);
    }

    this.executionId = stepExecution.getId();
    this.stepName = stepExecution.getStepName();
    this.status = stepExecution.getStatus();
    this.readCount = stepExecution.getReadCount();
    this.writeCount = stepExecution.getWriteCount();
    this.commitCount = stepExecution.getCommitCount();
    this.rollbackCount = stepExecution.getRollbackCount();
    this.readSkipCount = stepExecution.getReadSkipCount();
    this.processSkipCount = stepExecution.getProcessSkipCount();
    this.writeSkipCount = stepExecution.getWriteSkipCount();
    this.startTime = dateFormat.print(stepExecution.getStartTime().getTime());

    if (stepExecution.getEndTime() != null) {
        this.endTime = dateFormat.print(stepExecution.getEndTime().getTime());
    } else {
        this.endTime = "N/A";
    }

    this.lastUpdated = dateFormat.print(stepExecution.getLastUpdated().getTime());
    HashMap<String, Object> executionContextValues = new HashMap<String, Object>();

    for (Map.Entry<String, Object> stringObjectEntry : stepExecution.getExecutionContext().entrySet()) {
        executionContextValues.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
    }

    this.executionContext = executionContextValues;
    this.exitStatus = stepExecution.getExitStatus();
    this.terminateOnly = stepExecution.isTerminateOnly();
    this.filterCount = stepExecution.getFilterCount();
    this.failureExceptions = stepExecution.getFailureExceptions();
    this.version = stepExecution.getVersion();
}

From source file:org.springframework.format.datetime.joda.DateTimeFormatterFactory.java

License:Apache License

/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter/*from ww w . j  a  v a2s .c om*/
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
    DateTimeFormatter dateTimeFormatter = null;
    if (StringUtils.hasLength(this.pattern)) {
        dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
    } else if (this.iso != null && this.iso != ISO.NONE) {
        switch (this.iso) {
        case DATE:
            dateTimeFormatter = ISODateTimeFormat.date();
            break;
        case TIME:
            dateTimeFormatter = ISODateTimeFormat.time();
            break;
        case DATE_TIME:
            dateTimeFormatter = ISODateTimeFormat.dateTime();
            break;
        case NONE:
            /* no-op */
            break;
        default:
            throw new IllegalStateException("Unsupported ISO format: " + this.iso);
        }
    } else if (StringUtils.hasLength(this.style)) {
        dateTimeFormatter = DateTimeFormat.forStyle(this.style);
    }

    if (dateTimeFormatter != null && this.timeZone != null) {
        dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
    }
    return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}

From source file:org.springframework.format.datetime.joda.JodaTimeContext.java

License:Apache License

/**
 * Get the DateTimeFormatter with the this context's settings
 * applied to the base {@code formatter}.
 * @param formatter the base formatter that establishes default
 * formatting rules, generally context-independent
 * @return the contextual DateTimeFormatter
 *///  ww  w .  j  a v  a 2 s  .  c o  m
public DateTimeFormatter getFormatter(DateTimeFormatter formatter) {
    if (this.chronology != null) {
        formatter = formatter.withChronology(this.chronology);
    }
    if (this.timeZone != null) {
        formatter = formatter.withZone(this.timeZone);
    } else {
        LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
        if (localeContext instanceof TimeZoneAwareLocaleContext) {
            TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
            if (timeZone != null) {
                formatter = formatter.withZone(DateTimeZone.forTimeZone(timeZone));
            }
        }
    }
    return formatter;
}

From source file:org.springmodules.validation.util.condition.date.jodatime.IsAfterInstantCondition.java

License:Apache License

/**
 * Constructs a new IsAfterDateCondition with a given calendar to be checked against.
 *
 * @param earlier The calendar that this instantCondition will checkCalendar against.
 *///from   ww  w  . j  a v  a 2 s  . c o m
public IsAfterInstantCondition(Calendar earlier) {
    this.earlier = new DateTime(earlier.getTimeInMillis(), DateTimeZone.forTimeZone(earlier.getTimeZone()));
}

From source file:org.springmodules.validation.util.condition.date.jodatime.IsBeforeInstantCondition.java

License:Apache License

/**
 * Constructs a new IsBeforeDateCondition with a given calendar to be checked against.
 *
 * @param later The calendar that this instantCondition will checkCalendar against.
 *//*  www . j  a v  a  2 s .c om*/
public IsBeforeInstantCondition(Calendar later) {
    this.later = new DateTime(later.getTimeInMillis(), DateTimeZone.forTimeZone(later.getTimeZone()));
}

From source file:org.teiid.translator.odata.ODataExecutionFactory.java

License:Open Source License

/**
 *
 * @param value//from ww w  . j  a  va 2s.  c om
 * @param expectedType
 * @return
 */
public Object retrieveValue(Object value, Class<?> expectedType) {
    if (value == null) {
        return null;
    }
    if (value instanceof LocalDateTime) {
        DateTime dateTime = ((LocalDateTime) value).toDateTime(DateTimeZone.forTimeZone(this.timeZone));
        return new java.sql.Timestamp(dateTime.getMillis());
    }
    if (value instanceof LocalTime) {
        return new java.sql.Timestamp(((LocalTime) value).toDateTimeToday().getMillis());
    }
    if (value instanceof UnsignedByte) {
        return Short.valueOf(((UnsignedByte) value).shortValue());
    }
    return value;
}

From source file:org.thymeleaf.stripes.expression.JodaDates.java

License:Apache License

private DateTimeZone toTz(Object o) {
    if (o instanceof TimeZone)
        return DateTimeZone.forTimeZone((TimeZone) o);
    return DateTimeZone.forID(o.toString());
}

From source file:org.wicketopia.joda.util.format.JodaFormatSupport.java

License:Apache License

public T convertToObject(String value, Locale locale) {
    if (Strings.isEmpty(value)) {
        return null;
    }/*w ww.  ja  va 2s . co m*/

    DateTimeFormatter format = formatProvider.getFormatter();

    if (format == null) {
        throw new IllegalStateException("format must be not null");
    }
    format = format.withLocale(locale).withPivotYear(pivotYear);
    if (applyTimeZoneDifference) {
        TimeZone zone = getClientTimeZone();
        // instantiate now/ current time
        MutableDateTime dt = new MutableDateTime();
        if (zone != null) {
            // set time zone for client
            format = format.withZone(DateTimeZone.forTimeZone(zone));
            dt.setZone(DateTimeZone.forTimeZone(zone));
        }
        try {
            // parse date retaining the time of the submission
            int result = format.parseInto(dt, value, 0);
            if (result < 0) {
                throw new ConversionException(new ParseException("unable to parse date " + value, ~result));
            }
        } catch (RuntimeException e) {
            throw new ConversionException(e);
        }
        // apply the server time zone to the parsed value
        dt.setZone(getServerTimeZone());
        return translator.fromDateTime(dt.toDateTime());
    } else {
        try {
            DateTime date = format.parseDateTime(value);
            return date == null ? null : translator.fromDateTime(date);
        } catch (RuntimeException e) {
            throw new ConversionException(e);
        }
    }
}

From source file:org.wicketopia.joda.util.format.JodaFormatSupport.java

License:Apache License

@SuppressWarnings("unchecked")
public String convertToString(T object, Locale locale) {
    if (object == null) {
        return "";
    }//from  w  ww  .ja v  a  2  s . c  om
    DateTime dt = translator.toDateTime((T) object);
    DateTimeFormatter format = formatProvider.getFormatter();
    format = format.withPivotYear(pivotYear).withLocale(locale);
    if (applyTimeZoneDifference) {
        TimeZone zone = getClientTimeZone();
        if (zone != null) {
            format = format.withZone(DateTimeZone.forTimeZone(zone));
        }
    }
    return format.print(dt);
}