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:de.openali.odysseus.chart.ext.base.axisrenderer.DateTimeLabelCreator.java

License:Open Source License

/**
 * @see de.openali.odysseus.chart.ext.base.axisrenderer.ILabelCreator#getLabel(java.lang.Number,
 *      de.openali.odysseus.chart.framework.model.data.IDataRange)
 *///w w w .j  ava  2  s  .  c  o  m
@Override
public String getLabel(final Number value, final IDataRange<Number> range) {
    //    final TimeZone kalypsoTZ = KalypsoCorePlugin.getDefault().getTimeZone();
    //    final FixedDateTimeZone jodaTZ = new FixedDateTimeZone( kalypsoTZ.getID(), null, kalypsoTZ.getOffset(  value.longValue() ), kalypsoTZ.getOffset(  value.longValue() ) );
    //  
    final IDateTimeAxisField axisField = m_dateTimeFieldProvider.getDateTimeAxisField(range);
    final DateTimeZone zone = DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone());
    final DateTime dateTime = new DateTime(value.longValue(), zone);

    return dateTime.toString(axisField.getFormatString());
}

From source file:de.openali.odysseus.chart.ext.base.axisrenderer.DateTimeTickCalculator.java

License:Open Source License

private long getFirstRollValue(final IDateTimeAxisField axisField, final long start, final long end) {
    final DateTimeZone jodaTZ = DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone());
    final DateTimeField field = axisField.getFieldType().getField(GregorianChronology.getInstance(jodaTZ));
    final long firstRoll = field.roundFloor(start);
    if (firstRoll + end - start <= start)
        // out of range, precision too small so we return without adjustment
        // maybe try roundCeil instead
        return start;
    final int fieldValue = field.get(firstRoll);
    if (fieldValue == 0)
        return firstRoll;

    final int[] beginners = axisField.getBeginners();
    for (int i = 1; i < beginners.length; i++) {
        if (fieldValue < beginners[i]) {
            return field.add(firstRoll, beginners[i - 1] - fieldValue);
        }// ww  w  . j a  va  2s.c  o  m
    }

    return field.add(firstRoll, -fieldValue);
}

From source file:de.openali.odysseus.chart.ext.base.axisrenderer.DateTimeTickCalculator.java

License:Open Source License

/**
 * Calculates the ticks shown for the given Axis
 *//*from  www . j  av  a 2 s.  c om*/
@SuppressWarnings("rawtypes")
@Override
public Double[] calcTicks(final GC gc, final IAxis axis, final Number minDisplayInterval,
        final Point ticklabelSize) {
    final IDataRange<Number> numRange = axis.getNumericRange();
    if (numRange == null || numRange.getMin() == null || numRange.getMax() == null)
        return new Double[] {};

    final long start = numRange.getMin().longValue();
    final long end = numRange.getMax().longValue();

    final IDateTimeAxisField axisField = m_fieldTypeProvider.getDateTimeAxisField(numRange);

    final DateTimeZone jodaTZ = DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone());
    final DurationField field = axisField.getFieldType().getDurationType()
            .getField(GregorianChronology.getInstance(jodaTZ));

    final int tickCount = Math.max(1, field.getDifference(end, start));
    final int maximumTickCount = axis.getScreenHeight() / (ticklabelSize.x + 2/* Pixel */);
    final int[] rollOvers = axisField.getRollovers();

    final int rollOver = calculateRollover(tickCount, maximumTickCount, rollOvers);

    final List<Double> ticks = new ArrayList<>();
    Long tick = getFirstRollValue(axisField, start, end);
    ticks.add(tick.doubleValue());
    while (tick < end) {
        tick = field.add(tick, rollOver);
        ticks.add(tick.doubleValue());
    }

    return ticks.toArray(new Double[ticks.size()]);
}

From source file:de.taimos.dvalin.interconnect.model.DateTimeDeserializerWithTZ.java

License:Apache License

@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonToken t = jp.getCurrentToken();/*from  ww w . ja  va2 s .  c o  m*/
    if (t == JsonToken.VALUE_NUMBER_INT) {
        return new DateTime(jp.getLongValue(), DateTimeZone.forTimeZone(ctxt.getTimeZone()));
    }
    if (t == JsonToken.VALUE_STRING) {
        String str = jp.getText().trim();
        if (str.length() == 0) { // [JACKSON-360]
            return null;
        }
        // catch serialized time zones
        if ((str.charAt(str.length() - 6) == '+') || (str.charAt(str.length() - 1) == 'Z')
                || (str.charAt(str.length() - 6) == '-')) {
            return new DateTime(str);
        }
        return new DateTime(str, DateTimeZone.forTimeZone(ctxt.getTimeZone()));
    }
    ctxt.handleUnexpectedToken(this.handledType(), jp);
    // never reached
    return null;
}

From source file:de.taimos.dvalin.interconnect.model.DateTimeKeyDeserializer.java

License:Apache License

@Override
protected Object _parse(String key, DeserializationContext ctxt) throws Exception {
    if (key.length() == 0) { // [JACKSON-360]
        return null;
    }/* w  w  w  .j a v  a  2  s .c om*/
    return new DateTime(key, DateTimeZone.forTimeZone(ctxt.getTimeZone()));
}

From source file:fi.helsinki.opintoni.service.TimeService.java

License:Open Source License

public String toHelsinkiTimeFromUTC(DateTime dateTime) {
    return dateTime.toDateTime(DateTimeZone.forTimeZone(TimeZone.getTimeZone(HELSINKI_ZONE_ID)))
            .toString("dd.MM.yyyy HH:mm");
}

From source file:gobblin.converter.avro.JsonElementConversionFactory.java

License:Apache License

private static DateTimeZone getTimeZone(String id) {
    DateTimeZone zone;//from  w ww .  j  av  a  2 s  .co  m
    try {
        zone = DateTimeZone.forID(id);
    } catch (IllegalArgumentException e) {
        TimeZone timeZone = ZoneInfo.getTimeZone(id);

        //throw error if unrecognized zone
        if (timeZone == null) {
            throw new IllegalArgumentException("TimeZone " + id + " not recognized");
        }
        zone = DateTimeZone.forTimeZone(timeZone);
    }
    return zone;
}

From source file:griffon.plugins.jodatime.editors.DateTimeZonePropertyEditor.java

License:Apache License

protected void setValueInternal(Object value) {
    if (null == value) {
        super.setValueInternal(null);
    } else if (value instanceof DateTimeZone) {
        super.setValueInternal(value);
    } else if (value instanceof TimeZone) {
        super.setValueInternal(DateTimeZone.forTimeZone((TimeZone) value));
    } else if (value instanceof CharSequence) {
        handleAsString(String.valueOf(value));
    } else {// ww  w. j a v  a  2 s .co  m
        throw illegalValue(value, DateTimeZone.class);
    }
}

From source file:griffon.plugins.jodatime.JodatimeExtension.java

License:Apache License

public static DateTimeZone toDateTimeZone(TimeZone timeZone) {
    return DateTimeZone.forTimeZone(timeZone);
}

From source file:griffon.plugins.scaffolding.atoms.DateTimeZoneValue.java

License:Apache License

@Override
public void setValue(Object value) {
    if (value == null || value instanceof DateTimeZone) {
        super.setValue(value);
    } else if (value instanceof TimeZone) {
        super.setValue(DateTimeZone.forTimeZone((TimeZone) value));
    } else if (value instanceof CharSequence) {
        super.setValue(DateTimeZone.forID(value.toString()));
    } else {//w  ww  .  ja va2 s . c  o m
        throw new IllegalArgumentException("Invalid value " + value);
    }
}