List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:com.citrix.g2w.webdriver.pages.ScheduleAWebinarPage.java
License:Open Source License
/** * Sets the ending date/* w w w. j a va2s . com*/ * @param endDate DateTime */ private void setEndDate(final DateTime endDate) { DateTimeFormatter fmt = DateTimeFormat .forPattern(this.messages.getMessage("date.format.mask.dayInWeekMonthDayYear", null, this.locale)); ((JavascriptExecutor) this.driver) .executeScript("document.getElementById('recurrenceForm.endDate').value = '" + fmt.withLocale(this.locale).print(endDate) + "'"); }
From source file:com.citrix.g2w.webdriver.pages.ScheduleAWebinarPage.java
License:Open Source License
/** * Sets the starting time/* w ww . j av a2s. c o m*/ * @param startTime DateTime */ private void setStartTime(DateTime startTime) { this.setTextBoxValue("webinarTimesForm.dateTimes_0.startTime", DateTimeFormat .forPattern(this.messages.getMessage("date.format.mask.hourminute", null, this.locale)) .print(startTime)); }
From source file:com.citrix.g2w.webdriver.pages.ScheduleAWebinarPage.java
License:Open Source License
/** * Sets the ending time/*ww w. java 2s . co m*/ * @param endTime DateTime */ private void setEndTime(DateTime endTime) { this.setTextBoxValue("webinarTimesForm.dateTimes_0.endTime", DateTimeFormat .forPattern(this.messages.getMessage("date.format.mask.hourminute", null, this.locale)) .print(endTime)); }
From source file:com.citrix.g2w.webdriver.pages.ScheduleAWebinarPage.java
License:Open Source License
private boolean isAM(DateTime date) { return DateTimeFormat.forPattern("a").print(date).equalsIgnoreCase("AM"); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Parses a string for an embedded date and/or time contained within a * string such as "app.2008-05-01.log" or "app-20090624-051112.log.gz". * This method accepts a variety of date and time patterns that are valid * within the Joda DateTime library. For example, the string "app.2008-05-01.log" * would be a pattern of "yyyy-MM-dd" and the string "app-20090624-151112.log.gz" * would be a pattern of "yyyy-MM-dd-HHmmss". * @param string0 The string to parse/*from w ww.jav a 2 s . co m*/ * @param pattern The DateTime pattern embedded in the string such as * "yyyy-MM-dd". The pattern must be a valid DateTime Joda pattern. * @param zone The timezone the parsed date will be in * @return The parsed DateTime value * @throws IllegalArgumentException Thrown if the pattern is invalid or if * string did not contain an embedded date. */ public static DateTime parseEmbedded(String string0, String pattern, DateTimeZone zone) throws IllegalArgumentException { // compile a date time formatter -- which also will check that pattern DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern).withZone(zone); // // use the pattern to generate a regular expression now -- we'll do a // simple replacement of ascii characters with \\d // StringBuilder regex = new StringBuilder(pattern.length() * 2); for (int i = 0; i < pattern.length(); i++) { char c = pattern.charAt(i); if (Character.isLetter(c)) { regex.append("\\d"); } else { regex.append(c); } } // extract the date from the string Pattern p = Pattern.compile(regex.toString()); // Compiles regular expression into Pattern. Matcher m = p.matcher(string0); // Creates Matcher with subject s and Pattern p. if (!m.find()) { // if we get here, then no valid grouping was found throw new IllegalArgumentException( "String '" + string0 + "' did not contain an embedded date [regexPattern='" + regex.toString() + "', datePattern='" + pattern + "']"); } //logger.debug("Matching date: " + m.group()); // this group represents a string in the format YYYY-MM-DD String dateString = m.group(); // parse the string and return the Date return fmt.parseDateTime(dateString); }
From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java
License:Apache License
protected DateTimePeriod(DateTime start, DateTime end, DateTimeDuration duration, String keyPattern, String longNamePattern, String shortNamePattern, String indexNamePattern) { this.start = start; this.end = end; this.duration = duration; this.key = DateTimeFormat.forPattern(keyPattern).print(start); this.longName = DateTimeFormat.forPattern(longNamePattern).print(start); this.shortName = DateTimeFormat.forPattern(shortNamePattern).print(start); this.indexName = DateTimeFormat.forPattern(indexNamePattern).print(start); }
From source file:com.clustercontrol.hub.util.CollectStringDataParser.java
License:Open Source License
public CollectStringDataParser(LogFormat format) { this.format = format; Pattern timestampPattern = null; try {//from w w w. j av a 2 s . c om timestampPattern = format.getTimestampRegex() == null ? null : Pattern.compile(format.getTimestampRegex()); } catch (PatternSyntaxException e) { log.warn(String.format("invalid regex : ignored format.timestampRegex = %s", format.getTimestampRegex())); } finally { this.timestampPattern = timestampPattern; } DateTimeFormatter timestampFormatter = null; try { //??IllegalArgument??????null????? timestampFormatter = (format.getTimestampFormat() == null || format.getTimestampFormat().equals("")) ? null : DateTimeFormat.forPattern(format.getTimestampFormat()).withLocale(timestampLocale) .withDefaultYear(0); } catch (IllegalArgumentException e) { log.warn(String.format("invalid format : ignored format.timestampFormat = %s", format.getTimestampFormat())); } finally { this.timestampFormatter = timestampFormatter == null ? DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss.SSS").withLocale(timestampLocale) .withDefaultYear(0) : timestampFormatter; } Map<String, Pattern> keywordPatternMap = new TreeMap<String, Pattern>(); for (LogFormatKey keyword : format.getKeyPatternList()) { try { Pattern keywordPattern = keyword.getPattern() == null ? null : Pattern.compile(keyword.getPattern()); keywordPatternMap.put(keyword.getKey(), keywordPattern); } catch (PatternSyntaxException e) { log.warn(String.format("invalid regex : ignored keyword.regex = %s", keyword.getPattern())); } } this.keywordPatternMap = Collections.unmodifiableMap(keywordPatternMap); }
From source file:com.coderoad.automation.common.util.DateUtil.java
License:Open Source License
/** * Gets the calendar.//from ww w .java2s. co m * * @param dateTime the date time * @param pattern the pattern * @return the calendar * @throws ParseException the parse exception */ public static Calendar getCalendar(final String dateTime, String pattern) throws ParseException { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); DateTime dt = fmt.parseDateTime(dateTime); return dt.toCalendar(Locale.ENGLISH); }
From source file:com.coderoad.automation.common.util.DateUtil.java
License:Open Source License
/** * Gets the calendar./*from w ww . j a va 2 s .c o m*/ * * @param startTime the start time * @param minutes the minutes * @param pattern the pattern * @return the calendar */ public static Calendar getCalendar(Calendar startTime, int minutes, final String pattern) { Calendar endTime = null; DateTime start = new DateTime(startTime); DateTime end = start.plusMinutes(minutes); DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); fmt = fmt.withZoneUTC(); endTime = parseToUTCCalendar(fmt.print(end), pattern); return endTime; }
From source file:com.coderoad.automation.common.util.DateUtil.java
License:Open Source License
/** * Gets the UTC current time stamp.//www .ja va 2s .co m * * @param pattern the pattern * @return the UTC current time stamp */ public static String getUTCCurrentTimeStamp(String pattern) { DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); return fmt.print(new DateTime(DateTimeZone.UTC)); }