Example usage for org.joda.time DateTimeZone forID

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

Introduction

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

Prototype

@FromString
public static DateTimeZone forID(String id) 

Source Link

Document

Gets a time zone instance for the specified time zone id.

Usage

From source file:net.asfun.jangod.lib.filter.DatetimeFilter.java

License:Apache License

@Override
public Object filter(Object object, JangodInterpreter interpreter, String... arg) throws InterpretException {
    if (object == null) {
        return object;
    }/*from w  w  w.j a v  a  2 s  .co m*/
    if (object instanceof DateTime) { // joda DateTime
        DateTimeFormatter formatter;
        DateTimeFormatter a = DateTimeFormat.forPattern(interpreter.evaluateExpressionAsString(arg[0]));
        if (arg.length == 1) {
            DateTimeFormatter forPattern = a;
            JodaTimeContext jodaTimeContext = JodaTimeContextHolder.getJodaTimeContext();
            if (jodaTimeContext == null) {
                jodaTimeContext = new JodaTimeContext();
            }
            formatter = jodaTimeContext.getFormatter(forPattern);
        } else if (arg.length == 2) {
            formatter = a.withChronology(ISOChronology
                    .getInstance(DateTimeZone.forID(interpreter.evaluateExpressionAsString(arg[1]))));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return formatter.print((DateTime) object);
    } else {
        SimpleDateFormat sdf;
        if (arg.length == 1) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(interpreter.getConfiguration().getTimezone());
        } else if (arg.length == 2) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(TimeZone.getTimeZone(interpreter.evaluateExpressionAsString(arg[1])));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return sdf.format(object);
    }
}

From source file:net.bashtech.geobot.MessageReplaceParser.java

License:Open Source License

public static String handleDatetime(String message, String prefix, String suffix, String format) {

    int commandStart = message.indexOf(prefix);
    int commandEnd = message.indexOf(suffix);

    String replaced = message.substring(commandStart, commandEnd + suffix.length());

    DateTimeZone tz;/*  w  ww . ja  va2s . c om*/
    if (commandStart + prefix.length() < commandEnd) {
        String tzid = message.substring(commandStart + prefix.length(), commandEnd);
        try {
            tz = DateTimeZone.forID(tzid);
        } catch (IllegalArgumentException e) {
            tz = DateTimeZone.UTC;
        }
    } else {
        tz = DateTimeZone.UTC;
    }

    DateTimeFormatter fmt = DateTimeFormat.forPattern(format);
    fmt = fmt.withZone(tz);
    String dateStr = fmt.print(new DateTime());
    message = message.replace(replaced, dateStr);

    return message;
}

From source file:net.hellonico.jodatime.TimeLibrary.java

License:Open Source License

public DateTime getTime(String location) {
    DateTimeZone zone = DateTimeZone.forID(location);
    DateTime dt = new DateTime();
    return dt.withZone(zone);
}

From source file:net.jrkatz.minero.data.DbDebitProvider.java

License:Open Source License

Debit atCursor(@NonNull final Cursor cursor) {
    return new Debit(cursor.getLong(0), cursor.getLong(1), cursor.getLong(2), cursor.getInt(3),
            cursor.getString(4),// ww  w  . j  a  v  a  2  s . com
            new DateTime(cursor.getLong(5)).withZone(DateTimeZone.forID(cursor.getString(6))),
            cursor.isNull(7) ? null : cursor.getLong(7));
}

From source file:net.jrkatz.minero.data.Debit.java

License:Open Source License

protected Debit(Parcel in) {
    mId = in.readLong();//from   www  .j  a  v  a 2s.  c  om
    mBudgetId = in.readLong();
    mBudgetPeriodId = in.readLong();
    mAmount = in.readInt();
    mDescription = in.readString();
    mTime = new DateTime(in.readLong()).withZone(DateTimeZone.forID(in.readString()));
    mParentId = in.readLong();
}

From source file:net.solarnetwork.central.dras.mock.biz.MockDRASQueryBiz.java

License:Open Source License

/**
 * Constructor./*  w w w.  j a v  a2  s .c  o  m*/
 * 
 * @param observerBiz the observer biz to setup mock data with
 */
public MockDRASQueryBiz(MockDRASObserverBiz observerBiz) {
    DateTimeZone tz = DateTimeZone.forID("Pacific/Auckland");
    reportableInterval = new Interval(new DateTime(2011, 1, 1, 8, 0, 0, 0, tz),
            new DateTime(2011, 2, 1, 8, 0, 0, 0, tz));
    /*
    for ( Program program : observerBiz.getAllPrograms(null) ) {
       for ( NodeIdentity node : observerBiz.getProgramParticipants(program, null, null)) {
            
            
       }
    }
    */
}

From source file:net.solarnetwork.node.weather.wu.BasicWeatherUndergoundClient.java

License:Open Source License

private GeneralDayDatum parseForecast(final JsonNode node, final int dayOffset) {
    if (node == null) {
        return null;
    }//from   w w  w .  j a  v  a  2 s. c o m
    GeneralDayDatum datum = new GeneralDayDatum();

    JsonNode forecastNode = node.get("simpleforecast");
    if (forecastNode == null) {
        return null;
    }

    JsonNode dayArrayNode = forecastNode.get("forecastday");
    if (dayArrayNode == null || !dayArrayNode.isArray()) {
        return null;
    }
    JsonNode dayNode = dayArrayNode.get(dayOffset);

    JsonNode dateNode = dayNode.get("date");
    String tz = parseStringAttribute(dateNode, "tz_long");
    Long epoch = parseLongAttribute(dateNode, "epoch");
    if (tz != null && epoch != null) {
        LocalDate date = new LocalDate(epoch.longValue() * 1000, DateTimeZone.forID(tz));
        datum.setCreated(date.toDate());
    }

    datum.setRain(parseIntegerAttribute(dayNode.get("qpf_allday"), "mm"));

    datum.setSkyConditions(parseStringAttribute(dayNode, "conditions"));

    JsonNode snowNode = dayNode.get("snow_allday");
    if (snowNode != null) {
        Integer snowCm = parseIntegerAttribute(snowNode, "cm");
        if (snowCm != null) {
            // convert snow to mm
            datum.setSnow(snowCm.intValue() * 10);
        }
    }

    JsonNode tempNode = dayNode.get("high");
    if (tempNode != null) {
        datum.setTemperatureMaximum(parseBigDecimalAttribute(tempNode, "celsius"));
    }

    tempNode = dayNode.get("low");
    if (tempNode != null) {
        datum.setTemperatureMinimum(parseBigDecimalAttribute(tempNode, "celsius"));
    }

    JsonNode windNode = dayNode.get("avewind");
    if (windNode != null) {
        datum.setWindDirection(parseIntegerAttribute(windNode, "degrees"));
        datum.setWindSpeed(parseWindSpeed(windNode, "kph"));
    }

    JsonNode txtNode = node.get("txt_forecast");
    if (txtNode != null) {
        JsonNode txtDayArrayNode = txtNode.get("forecastday");
        if (txtDayArrayNode != null && txtDayArrayNode.isArray()) {
            // txt day nodes come in pairs, one for day one for night; we only get day values
            JsonNode txtDayNode = txtDayArrayNode.get(dayOffset * 2);
            if (txtDayNode != null) {
                // TODO: support imperial description gathering via class property
                datum.setBriefOverview(parseStringAttribute(txtDayNode, "fcttext_metric"));
            }
        }
    }

    return datum;
}

From source file:openmarker.tea.runtime.DefaultContext.java

License:Apache License

public void dateFormat(String format, String timeZoneID) {
    DateTimeZone zone;//  w  w  w . ja v  a  2s .  c o m
    if (timeZoneID != null) {
        zone = DateTimeZone.forID(timeZoneID);
    } else {
        zone = DateTimeZone.getDefault();
    }
    mDateTimeZone = zone;

    /* --Original before joda upgrade
    DateTimeFormat dtFormat;
    if (mLocale == null) {
    dtFormat = DateTimeFormat.getInstance(zone); --orig
    }
    else {
    dtFormat = DateTimeFormat.getInstance(zone, mLocale);
    }
            
    if (format == null) {
    format = dtFormat.getPatternForStyle("LL"); --orig
    }*/

    if (format == null) {
        format = DateTimeFormat.patternForStyle("LL", mLocale);
    }
    DateTimeFormatter formatter = DateTimeFormat.forPattern(format).withZone(zone);
    if (mLocale != null) {
        formatter = formatter.withLocale(mLocale);
    }

    mDateTimeFormatter = formatter;
    mDateTimePattern = format;
}

From source file:org.akaza.openclinica.logic.expressionTree.OpenClinicaBeanVariableNode.java

License:LGPL

private Object calculateVariable() {
    if (number.equals("_CURRENT_DATE")) {
        String ssTimeZone = getExpressionBeanService().getSSTimeZone();
        if (ssTimeZone == "" || ssTimeZone == null)
            ssTimeZone = TimeZone.getDefault().getID();

        DateTimeZone ssZone = DateTimeZone.forID(ssTimeZone);
        DateMidnight dm = new DateMidnight(ssZone);
        DateTimeFormatter fmt = ISODateTimeFormat.date();
        return fmt.print(dm);
    }/*  w w  w .  j a v  a 2s.co  m*/
    return null;
}

From source file:org.akaza.openclinica.logic.expressionTree.OpenClinicaBeanVariableNode.java

License:LGPL

private String testCalculateVariable() {
    if (number.equals("_CURRENT_DATE")) {
        String ssTimeZone = getExpressionBeanService().getSSTimeZone();
        if (ssTimeZone == "" || ssTimeZone == null)
            ssTimeZone = TimeZone.getDefault().getID();

        DateTimeZone ssZone = DateTimeZone.forID(ssTimeZone);
        DateMidnight dm = new DateMidnight(ssZone);
        DateTimeFormatter fmt = ISODateTimeFormat.date();
        return fmt.print(dm);
    }/*from w w  w  .j  av a 2  s.  com*/
    return null;
}