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:com.cronutils.htime.DateTimeFormatParser.java

License:Apache License

@VisibleForTesting
boolean isTimezone(String string) {
    try {//from   w w w . j a  v a  2s  .  c  om
        DateTimeZone.forID(string);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}

From source file:com.cronutils.mapper.format.DateTimeFormatLocaleStrategy.java

License:Apache License

private boolean isTimezone(String string) {
    try {/*w w  w . j  a v  a  2  s  .  co  m*/
        DateTimeZone.forID(string);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}

From source file:com.dalendev.meteotndata.service.TimeService.java

License:Open Source License

public static Long getMillis(final LocalDateTime date) {
    return date.toDateTime(DateTimeZone.forID("Europe/Rome")).getMillis();
}

From source file:com.datastax.driver.extras.codecs.joda.DateTimeCodec.java

License:Apache License

@Override
protected DateTime deserializeAndSetField(ByteBuffer input, DateTime target, int index,
        ProtocolVersion protocolVersion) {
    if (index == 0) {
        long millis = bigint().deserializeNoBoxing(input, protocolVersion);
        return new DateTime(millis);
    }/*from w  ww .j  av  a2s. c  om*/
    if (index == 1) {
        String zoneId = varchar().deserialize(input, protocolVersion);
        return target.withZone(DateTimeZone.forID(zoneId));
    }
    throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index);
}

From source file:com.datastax.driver.extras.codecs.joda.DateTimeCodec.java

License:Apache License

@Override
protected DateTime parseAndSetField(String input, DateTime target, int index) {
    if (index == 0) {
        // strip enclosing single quotes, if any
        if (ParseUtils.isQuoted(input))
            input = ParseUtils.unquote(input);
        if (isLongLiteral(input)) {
            try {
                long millis = Long.parseLong(input);
                return new DateTime(millis);
            } catch (NumberFormatException e) {
                throw new InvalidTypeException(
                        String.format("Cannot parse timestamp value from \"%s\"", input));
            }//from   w  w  w.  j a  v  a 2 s .c o m
        }
        try {
            return parser.parseDateTime(input);
        } catch (RuntimeException e) {
            throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", target));
        }
    }
    if (index == 1) {
        String zoneId = varchar().parse(input);
        // Joda time does not recognize "Z"
        if ("Z".equals(zoneId))
            return target.withZone(DateTimeZone.UTC);
        return target.withZone(DateTimeZone.forID(zoneId));
    }
    throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index);
}

From source file:com.davis.bluefolder.BlueUtils.java

public static String contructDatesForSearch(String start, String end) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("MM-dd-yyyy hh:mma");
    DateTimeZone timeZone = DateTimeZone.forID("America/New_York"); // Specify or else the JVM's default will apply.
    DateTime dateTime = new DateTime(new java.util.Date(), timeZone); // Today's Date
    DateTime pastDate = dateTime.minusDays(14); // 2 weeks ago

    String endDate = null;/*  w  ww .  j a va2 s. c o m*/
    String startDate = null;
    if (start != null && !start.trim().equalsIgnoreCase("")) {
        if (end != null && !end.trim().equalsIgnoreCase("")) {
            startDate = fmt.parseDateTime(start).toString();
            endDate = fmt.parseDateTime(end).toString();
        } else {
            endDate = fmt.print(dateTime);
            startDate = fmt.print(pastDate);
        }
    } else {
        endDate = fmt.print(dateTime);
        startDate = fmt.print(pastDate);
    }

    //dateTimeClosed
    String date = " <dateRange dateField=\"dateTimeCreated\">" + "<startDate>" + startDate + "</startDate>"
            + "<endDate>" + endDate + "</endDate>" + "</dateRange>";

    return date;

}

From source file:com.dtstack.jlogstash.date.FormatParser.java

License:Apache License

public FormatParser(String format, String timezone, String locale) {
    this.formatter = DateTimeFormat.forPattern(format);

    if (timezone != null) {
        this.formatter = this.formatter.withZone(DateTimeZone.forID(timezone));
    } else {/*w w  w  . j  ava2 s  .c om*/
        this.formatter = this.formatter.withOffsetParsed();
    }

    if (locale != null) {
        this.formatter = this.formatter.withLocale(Locale.forLanguageTag(locale));
    }
}

From source file:com.dtstack.jlogstash.date.ISODateParser.java

License:Apache License

public ISODateParser(String timezone) {

    this.formatter = ISODateTimeFormat.dateTimeParser();

    if (timezone != null) {
        this.formatter = this.formatter.withZone(DateTimeZone.forID(timezone));
    } else {/*from w  ww. j ava  2  s.c o m*/
        this.formatter = this.formatter.withOffsetParsed();
    }
}

From source file:com.dtstack.jlogstash.render.Formatter.java

License:Apache License

public static String format(Map event, String format, String Timezone) {
    Matcher m = p.matcher(format);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String match = m.group();
        String key = (String) match.subSequence(2, match.length() - 1);
        if (key.equalsIgnoreCase("+s")) {
            Object o = event.get("@timestamp");
            if (o.getClass() == Long.class) {
                m.appendReplacement(sb, o.toString());
            }/*from  w  w  w.  ja v  a  2 s .  c om*/
        } else if (key.startsWith("+")) {
            DateTimeFormatter formatter = DateTimeFormat.forPattern((String) key.subSequence(1, key.length()))
                    .withZone(DateTimeZone.forID(Timezone));
            Object o = event.get("@timestamp");
            if (o == null) {
                DateTime timestamp = new DateTime();
                m.appendReplacement(sb, timestamp.toString(formatter));
            } else {
                if (o.getClass() == DateTime.class) {
                    m.appendReplacement(sb, ((DateTime) o).toString(formatter));
                } else if (o.getClass() == Long.class) {
                    DateTime timestamp = new DateTime((Long) o);
                    m.appendReplacement(sb, timestamp.toString(formatter));
                } else if (o.getClass() == String.class) {
                    DateTime timestamp = ISOformatter.parseDateTime((String) o);
                    m.appendReplacement(sb, timestamp.toString(formatter));
                }
            }
        } else if (event.containsKey(key)) {
            m.appendReplacement(sb, event.get(key).toString());
        }

    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.ecofactor.qa.automation.util.CustomReport.java

License:Open Source License

/**
 * Write param details.//from   ww  w  .  j  a  v a2 s.c o  m
 */
protected void writeParamDetails() {

    long totalDuration = 0;
    for (SuiteResult suiteResult : suiteResults) {
        for (TestResult testResult : suiteResult.getTestResults()) {
            totalDuration += testResult.getDuration();
        }
    }

    String env = SystemUtil.getProperty("TestEnv");
    // String schema = ParamUtil.getSchema();

    String slave = SystemUtil.getProperty("label");
    if (slave.equalsIgnoreCase("-")) {
        slave = SystemUtil.getProperty("nodeName");
    }
    long endVal = Calendar.getInstance().getTimeInMillis();
    long startVal = endVal - totalDuration;

    String suiteLevel = System.getProperty("suiteLevel");
    if (suiteLevel == null || suiteLevel.isEmpty() || suiteLevel.equalsIgnoreCase("false")) {
        summaryWritter.print(GenerateHeader.writeBody(getJenkinsJobName()));
    }

    String startTime = DateUtil.formatToZone(startVal, DateTimeZone.forID("America/Los_Angeles"),
            DateUtil.LARGE_FORMAT);
    String endTime = DateUtil.formatToZone(endVal, DateTimeZone.forID("America/Los_Angeles"),
            DateUtil.HOUR_FORMAT);
    String resultMessage = "<a style=\"font-weight:bold\" id=\"summary\" name=\"summary\">Results executed on "
            + startTime + " to " + endTime + "</a>";

    String os = SystemUtil.getOSType().toString();
    String browser = SystemUtil.getProperty("browser");

    String jobName = getJenkinsJobName();
    String jenkinsUrl = SystemUtil.getProperty("jenkinsUrl");
    String consoleURL = "-";
    if (!jenkinsUrl.equalsIgnoreCase("-")) {
        consoleURL = "<a style=\"font-weight:bold\" target=\"_blank\" href=\"" + jenkinsUrl
                + "console\">Console</a>";
        jenkinsUrl = "<a style=\"font-weight:bold\" target=\"_blank\" href=\"" + jenkinsUrl + "\">Jenkins</a>";
    }

    StringBuilder builder = new StringBuilder();
    builder.append("<table width=\"100%\" style=\"border-collapse:collapse;empty-cells:show\">"
            + "<tr><td colspan=\"10\" style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">"
            + resultMessage
            + "</td></tr><tr><td colspan=\"10\" align=\"center\" style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom;font-weight:bold;background-color:#dededa\">Setup Summary</td></tr>"
            + "<tr>"
            + "<th style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">Environment</th>"
            + "<th style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">Slave</th>"
            + "<th style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">OS</th>"
            + "<th style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">Browser</th>"
            + "<th style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">Job Name</th>"
            + "<th style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">Jenkins URL</th>"
            + "<th style=\"border:1px solid #009;padding:.25em .5em;vertical-align:bottom\">Console URL</th></tr>"
            + "<tr>" + "<td style=\"border:1px solid #009;padding:.25em .5em;vertical-align:top\"> " + env
            + "</td>" + "<td style=\"border:1px solid #009;padding:.25em .5em;vertical-align:top\">" + slave
            + "</td> <td style=\"border:1px solid #009;padding:.25em .5em;vertical-align:top\">" + os + "</td>"
            + "<td style=\"border:1px solid #009;padding:.25em .5em;vertical-align:top\">" + browser + "</td>"
            + "<td style=\"border:1px solid #009;padding:.25em .5em;vertical-align:top;font-weight:bold;background-color:#8FF3F8\">"
            + jobName + "</td>" + "<td style=\"border:1px solid #009;padding:.25em .5em;vertical-align:top\">"
            + jenkinsUrl + "</td>"
            + "<td style=\"border:1px solid #009;padding:.25em .5em;vertical-align:top\">" + consoleURL
            + "</td></tr></table>");

    summaryWritter.print(builder.toString());
}