Example usage for org.joda.time DateTimeZone toTimeZone

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

Introduction

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

Prototype

public java.util.TimeZone toTimeZone() 

Source Link

Document

Get the datetime zone as a java.util.TimeZone .

Usage

From source file:ch.corten.aha.worldclock.TimeZoneInfo.java

License:Open Source License

public static String getDescription(DateTimeZone tz) {
    // The Java TimeZones gives a better description (and knows more time zones)
    TimeZone timeZone = tz.toTimeZone();
    if (timeZone.useDaylightTime() && timeZone.inDaylightTime(new Date())) {
        return timeZone.getDisplayName(true, TimeZone.LONG);
    }/*from   w w w  .j  ava2s  .  c  o m*/
    return timeZone.getDisplayName();
}

From source file:ch.corten.aha.worldclock.TimeZoneInfo.java

License:Open Source License

/**
 * Convert a joda-time {@link org.joda.time.DateTimeZone} to an equivalent Java {@link java.util.TimeZone}.
 *
 * @param dateTimeZone a joda-time {@link org.joda.time.DateTimeZone}
 * @param time         the time when the time zones should be equivalent.
 * @return a Java {@link java.util.TimeZone} with the same offset for the given time.
 *///from  w  w  w  .  ja  v a  2 s.com
public static TimeZone convertToJavaTimeZone(DateTimeZone dateTimeZone, long time) {
    TimeZone timeZone = dateTimeZone.toTimeZone();
    long offset = dateTimeZone.getOffset(time);
    if (timeZone.getOffset(time) == offset) {
        return timeZone;
    }
    String[] ids = TimeZone.getAvailableIDs((int) offset);
    Log.d(TZ_ID_TAG, dateTimeZone.getID() + ": " + Arrays.toString(ids));
    for (String id : ids) {
        TimeZone tz = TimeZone.getTimeZone(id);
        if (tz.getOffset(time) == offset) {
            timeZone = tz;
            Log.d(TZ_ID_TAG, "Found time zone " + tz.getID() + " for " + dateTimeZone.getID() + " with offset: "
                    + offset);
            break;
        }
    }
    return timeZone;
}

From source file:com.nominanuda.lang.CronExpr.java

License:Apache License

private CronExpr(String cronExpression, DateTimeZone dtz) throws IllegalArgumentException {
    try {// w  w  w .j a  v  a2s .c  o  m
        quartzExpr = new CronExpression(cronExpression);
        quartzExpr.setTimeZone(dtz.toTimeZone());
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}

From source file:fi.hsl.parkandride.core.domain.DefaultTimeZoneDateTimeSerializer.java

License:EUPL

private static JacksonJodaFormat formatterWithTimeZone(DateTimeZone timeZone) {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withZone(timeZone);
    return new JacksonJodaFormat(new JacksonJodaFormat(formatter), timeZone.toTimeZone());
}

From source file:org.apache.isis.applib.Defaults.java

License:Apache License

public static void setTimeZone(final DateTimeZone timezone) {
    timeZone = timezone;/*from   ww w.j  a va  2 s . c om*/
    calendar = Calendar.getInstance(timezone.toTimeZone());
}

From source file:org.apache.isis.objectstore.sql.Defaults.java

License:Apache License

public static void setTimeZone(final DateTimeZone timezone) {
    dateTimeZone = timezone;/*from w w  w  .  j  a v a 2  s .  c om*/
    calendar = Calendar.getInstance(timezone.toTimeZone());
}

From source file:org.apache.isis.schema.utils.jaxbadapters.JodaDateTimeXMLGregorianCalendarAdapter.java

License:Apache License

public static XMLGregorianCalendar print(final DateTime dateTime) {
    if (dateTime == null)
        return null;

    final long millis = dateTime.getMillis();
    final DateTimeZone dateTimeZone = dateTime.getZone();

    final TimeZone timeZone = dateTimeZone.toTimeZone();
    final GregorianCalendar calendar = new GregorianCalendar(timeZone);
    calendar.setTimeInMillis(millis);// w ww .  jav  a  2  s.c o m

    return new XMLGregorianCalendarImpl(calendar);
}

From source file:org.elasticsearch.xpack.sql.execution.search.extractor.CompositeKeyExtractor.java

License:Open Source License

CompositeKeyExtractor(StreamInput in) throws IOException {
    key = in.readString();/*from   ww w .  j  a  va2s. c o  m*/
    property = in.readEnum(Property.class);
    if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
        if (in.readBoolean()) {
            timeZone = TimeZone.getTimeZone(in.readString());
        } else {
            timeZone = null;
        }
    } else {
        DateTimeZone dtz = in.readOptionalTimeZone();
        if (dtz == null) {
            timeZone = null;
        } else {
            timeZone = dtz.toTimeZone();
        }
    }
}

From source file:org.gephi.desktop.datalab.ConfigurationPanel.java

License:Open Source License

/**
 * Creates new form ConfigurationPanel/*from  w  w w .  jav  a  2  s . c  om*/
 */
public ConfigurationPanel(final DataTableTopComponent dataTableTopComponent, final GraphModel graphModel) {
    this.dataTableTopComponent = dataTableTopComponent;
    this.graphModel = graphModel;
    initComponents();

    for (TimeFormat tf : TimeFormat.values()) {
        timeFormatComboBox.addItem(new TimeFormatWrapper(tf));
    }
    timeFormatComboBox.setSelectedItem(new TimeFormatWrapper(graphModel.getTimeFormat()));

    timeFormatComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            graphModel.setTimeFormat(((TimeFormatWrapper) timeFormatComboBox.getSelectedItem()).timeFormat);
            dataTableTopComponent.refreshCurrentTable();
        }
    });

    onlyVisibleCheckBox.setSelected(dataTableTopComponent.isShowOnlyVisible());
    useSparklinesCheckBox.setSelected(dataTableTopComponent.isUseSparklines());
    timeIntervalsGraphicsCheckBox.setSelected(dataTableTopComponent.isTimeIntervalGraphics());
    showEdgesNodesLabelsCheckBox.setSelected(dataTableTopComponent.isShowEdgesNodesLabels());

    //Timezone:
    long currentTimestamp = System.currentTimeMillis();
    DateTimeZone currentTimeZone = graphModel.getTimeZone();

    buildTimeZoneList();
    timeZoneComboBox.setSelectedItem(new TimeZoneWrapper(currentTimeZone.toTimeZone(), currentTimestamp));

    timeZoneComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            TimeZone selected = ((TimeZoneWrapper) timeZoneComboBox.getSelectedItem()).timeZone;
            graphModel.setTimeZone(DateTimeZone.forTimeZone(selected));
            dataTableTopComponent.refreshCurrentTable();
        }
    });

    //Time representation:
    for (TimeRepresentation tr : TimeRepresentation.values()) {
        timeRepresentationComboBox.addItem(new TimeRepresentationWrapper(tr));
    }
    timeRepresentationComboBox.setSelectedItem(
            new TimeRepresentationWrapper(graphModel.getConfiguration().getTimeRepresentation()));

    if (canChangeTimeRepresentation(graphModel)) {
        timeRepresentationComboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                Configuration c = graphModel.getConfiguration();
                c.setTimeRepresentation(((TimeRepresentationWrapper) timeRepresentationComboBox
                        .getSelectedItem()).timeRepresentation);
                graphModel.setConfiguration(c);
            }
        });
    } else {
        timeRepresentationComboBox.setEnabled(false);
        timeRepresentationComboBox.setToolTipText(NbBundle.getMessage(ConfigurationPanel.class,
                "ConfigurationPanel.timeRepresentation.disabled.tooltip"));
    }
}

From source file:org.graylog.plugins.pipelineprocessor.functions.dates.FlexParseDate.java

License:Open Source License

@Override
protected DateTime evaluate(FunctionArgs args, EvaluationContext context, DateTimeZone timezone) {
    final String time = valueParam.required(args, context);

    final List<DateGroup> dates = new Parser(timezone.toTimeZone()).parse(time);
    if (dates.size() == 0) {
        final Optional<DateTime> defaultTime = defaultParam.optional(args, context);
        if (defaultTime.isPresent()) {
            return defaultTime.get();
        }/*w w w .j  ava2s .c om*/
        // TODO really? this should probably throw an exception of some sort to be handled in the interpreter
        return null;
    }
    return new DateTime(dates.get(0).getDates().get(0), timezone);
}