Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat forPattern.

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

From source file:com.manydesigns.elements.fields.AbstractDateField.java

License:Open Source License

public AbstractDateField(PropertyAccessor accessor, Mode mode, String prefix) {
    super(accessor, mode, prefix);

    DateFormat dateFormatAnnotation = accessor.getAnnotation(DateFormat.class);
    if (dateFormatAnnotation != null) {
        datePattern = dateFormatAnnotation.value();
    } else {//from w  w  w. ja  va  2s. co m
        Configuration elementsConfiguration = ElementsProperties.getConfiguration();
        datePattern = elementsConfiguration.getString(ElementsProperties.FIELDS_DATE_FORMAT);
    }
    dateTimeFormatter = DateTimeFormat.forPattern(datePattern);
    setSize(dateTimeFormatter.getParser().estimateParsedLength());

    containsTime = datePattern.contains("HH") || datePattern.contains("mm") || datePattern.contains("ss");
}

From source file:com.manydesigns.elements.fields.DateField.java

License:Open Source License

public DateField(PropertyAccessor accessor, Mode mode, String prefix) {
    super(accessor, mode, prefix);

    DateFormat dateFormatAnnotation = accessor.getAnnotation(DateFormat.class);
    if (dateFormatAnnotation != null) {
        datePattern = dateFormatAnnotation.value();
    } else {//from www.j a  v  a2  s  .  c  o m
        Configuration elementsConfiguration = ElementsProperties.getConfiguration();
        datePattern = elementsConfiguration.getString(ElementsProperties.FIELDS_DATE_FORMAT);
    }
    dateTimeFormatter = DateTimeFormat.forPattern(datePattern);
    setMaxLength(dateTimeFormatter.getParser().estimateParsedLength());

    containsTime = datePattern.contains("HH") || datePattern.contains("mm") || datePattern.contains("ss");

    String tmpPattern = datePattern;
    if (tmpPattern.contains("MM")) {
        tmpPattern = tmpPattern.replaceAll("MM", "mm");
    }
    jsDatePattern = tmpPattern;
}

From source file:com.manydesigns.elements.fields.search.AbstractDateSearchField.java

License:Open Source License

public AbstractDateSearchField(PropertyAccessor accessor, String prefix) {
    super(accessor, prefix);

    DateFormat dateFormatAnnotation = accessor.getAnnotation(DateFormat.class);
    if (dateFormatAnnotation != null) {
        datePattern = dateFormatAnnotation.value();
    } else {/*from   w w w. jav  a 2  s. c om*/
        Configuration elementsConfiguration = ElementsProperties.getConfiguration();
        datePattern = elementsConfiguration.getString(ElementsProperties.FIELDS_DATE_FORMAT);
    }
    dateTimeFormatter = DateTimeFormat.forPattern(datePattern);
    setSize(dateTimeFormatter.getParser().estimateParsedLength());

    containsTime = datePattern.contains("HH") || datePattern.contains("mm") || datePattern.contains("ss");
}

From source file:com.manydesigns.elements.fields.search.DateSearchField.java

License:Open Source License

public DateSearchField(PropertyAccessor accessor, String prefix) {
    super(accessor, prefix);

    DateFormat dateFormatAnnotation = accessor.getAnnotation(DateFormat.class);
    if (dateFormatAnnotation != null) {
        datePattern = dateFormatAnnotation.value();
    } else {/*w ww.  j  a  v a 2s.com*/
        Configuration elementsConfiguration = ElementsProperties.getConfiguration();
        datePattern = elementsConfiguration.getString(ElementsProperties.FIELDS_DATE_FORMAT);
    }
    dateTimeFormatter = DateTimeFormat.forPattern(datePattern);
    maxLength = dateTimeFormatter.getParser().estimateParsedLength();

    containsTime = datePattern.contains("HH") || datePattern.contains("mm") || datePattern.contains("ss");

    String tmpPattern = datePattern;
    if (tmpPattern.contains("yyyy")) {
        tmpPattern = tmpPattern.replaceAll("yyyy", "yy");
    }
    if (tmpPattern.contains("MM")) {
        tmpPattern = tmpPattern.replaceAll("MM", "mm");
    }
    if (tmpPattern.contains("dd")) {
        tmpPattern = tmpPattern.replaceAll("dd", "dd");
    }
    jsDatePattern = tmpPattern;
}

From source file:com.maxl.java.amikodesk.AMiKoDesk.java

License:Open Source License

static String getTitle(String key) {
    String updateTime = m_prefs.get("updateTime", "nie");
    DateTime uT = new DateTime(updateTime);
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy HH:mm:ss");
    String title = m_rb.getString(key) + " (aktualisiert am " + fmt.print(uT) + ")";
    return title;
}

From source file:com.meetingninja.csse.meetings.MeetingItemAdapter.java

License:Apache License

private String getTimeSpan(long start, long end, boolean allDay) {
    StringBuilder spanBuilder = new StringBuilder();
    boolean is24 = android.text.format.DateFormat.is24HourFormat(context.getApplicationContext());
    DateTimeFormatter timeFormat = is24 ? MyDateUtils.JODA_24_TIME_FORMAT : MyDateUtils.JODA_12_TIME_FORMAT;
    DateTimeFormatter dateFormat = DateTimeFormat.forPattern("MMMM dd, yyyy");
    spanBuilder.append(dateFormat.print(start));
    if (!allDay) {
        spanBuilder.append(", " + timeFormat.print(start) + " - ");
        spanBuilder.append(dateFormat.print(end));
        spanBuilder.append(", " + timeFormat.print(end));
    }//from  w w  w.  ja v a  2 s  .co  m

    return spanBuilder.toString();

}

From source file:com.meisolsson.githubsdk.core.FormattedTimeAdapter.java

License:Apache License

@FromJson
@FormattedTime//  w  ww .  j  a v a  2s  .  co  m
Date fromJson(String time) {
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
    DateTime t = format.withZoneUTC().parseDateTime(time);
    return t.toDate();
}

From source file:com.meisolsson.githubsdk.core.FormattedTimeAdapter.java

License:Apache License

@ToJson
String toJson(@FormattedTime Date date) {
    DateTimeFormatter formats = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
    return formats.print(date.getTime());
}

From source file:com.metamx.common.parsers.TimestampParser.java

License:Apache License

public static Function<String, DateTime> createTimestampParser(final String format) {
    if (format.equalsIgnoreCase("auto")) {
        // Could be iso or millis
        return new Function<String, DateTime>() {
            @Override//from   ww w.  ja v a2s . c o  m
            public DateTime apply(String input) {
                Preconditions.checkArgument(input != null && !input.isEmpty(), "null timestamp");

                for (int i = 0; i < input.length(); i++) {
                    if (input.charAt(i) < '0' || input.charAt(i) > '9') {
                        return new DateTime(ParserUtils.stripQuotes(input));
                    }
                }

                return new DateTime(Long.parseLong(input));
            }
        };
    } else if (format.equalsIgnoreCase("iso")) {
        return new Function<String, DateTime>() {
            @Override
            public DateTime apply(String input) {
                Preconditions.checkArgument(input != null && !input.isEmpty(), "null timestamp");
                return new DateTime(ParserUtils.stripQuotes(input));
            }
        };
    } else if (format.equalsIgnoreCase("posix") || format.equalsIgnoreCase("millis")
            || format.equalsIgnoreCase("nano")) {
        final Function<Number, DateTime> numericFun = createNumericTimestampParser(format);
        return new Function<String, DateTime>() {
            @Override
            public DateTime apply(String input) {
                Preconditions.checkArgument(input != null && !input.isEmpty(), "null timestamp");
                return numericFun.apply(Long.parseLong(ParserUtils.stripQuotes(input)));
            }
        };
    } else if (format.equalsIgnoreCase("ruby")) {
        // Numeric parser ignores millis for ruby.
        final Function<Number, DateTime> numericFun = createNumericTimestampParser(format);
        return new Function<String, DateTime>() {
            @Override
            public DateTime apply(String input) {
                Preconditions.checkArgument(input != null && !input.isEmpty(), "null timestamp");
                return numericFun.apply(Double.parseDouble(ParserUtils.stripQuotes(input)));
            }
        };
    } else {
        try {
            final DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
            return new Function<String, DateTime>() {
                @Override
                public DateTime apply(String input) {
                    Preconditions.checkArgument(input != null && !input.isEmpty(), "null timestamp");
                    return formatter.parseDateTime(ParserUtils.stripQuotes(input));
                }
            };
        } catch (Exception e) {
            throw new IAE(e, "Unable to parse timestamps with format [%s]", format);
        }
    }
}

From source file:com.metamx.druid.indexer.path.GranularityPathSpec.java

License:Open Source License

@Override
public Job addInputPaths(HadoopDruidIndexerConfig config, Job job) throws IOException {
    final Set<Interval> intervals = Sets.newTreeSet(Comparators.intervals());
    for (Interval segmentInterval : config.getSegmentGranularIntervals()) {
        for (Interval dataInterval : dataGranularity.getIterable(segmentInterval)) {
            intervals.add(dataInterval);
        }/*from ww  w.j a va 2 s . c  om*/
    }

    Path betaInput = new Path(inputPath);
    FileSystem fs = betaInput.getFileSystem(job.getConfiguration());
    Set<String> paths = Sets.newTreeSet();
    Pattern fileMatcher = Pattern.compile(filePattern);

    DateTimeFormatter customFormatter = null;
    if (pathFormat != null) {
        customFormatter = DateTimeFormat.forPattern(pathFormat);
    }

    for (Interval interval : intervals) {
        DateTime t = interval.getStart();
        String intervalPath = null;
        if (customFormatter != null) {
            intervalPath = customFormatter.print(t);
        } else {
            intervalPath = dataGranularity.toPath(t);
        }

        Path granularPath = new Path(betaInput, intervalPath);
        log.info("Checking path[%s]", granularPath);
        for (FileStatus status : FSSpideringIterator.spiderIterable(fs, granularPath)) {
            final Path filePath = status.getPath();
            if (fileMatcher.matcher(filePath.toString()).matches()) {
                paths.add(filePath.toString());
            }
        }
    }

    for (String path : paths) {
        log.info("Appending path[%s]", path);
        FileInputFormat.addInputPath(job, new Path(path));
    }

    return job;
}