List of usage examples for org.joda.time DateTime parse
public static DateTime parse(String str, DateTimeFormatter formatter)
From source file:eafit.cdei.util.IntervalGenerator.java
public static List<Interval> getIntervals(List<String> days, Time startTime, Time stopTime) { DateTimeFormatter fmt = DateTimeFormat.forPattern("YY-MM-DDH:mm:ss"); List<Interval> tmpMeetTimeIntervals = new ArrayList<Interval>(); LocalDate mondayDate = LocalDate.parse("2014-10-20"); for (int x = 0; x <= 5; x++) { LocalDate tmpStartDate = mondayDate.plusDays(x); String tmpDay = tmpStartDate.toString("EEEE"); if (days.contains(tmpDay)) { DateTime tmpStartDateTime = DateTime.parse( tmpStartDate.toString("YY-MM-DD") + LocalTime.fromDateFields(startTime).toString("H:mm:ss"), fmt);/*from www .j a va 2 s. c o m*/ DateTime tmpStopDateTime = DateTime.parse( tmpStartDate.toString("YY-MM-DD") + LocalTime.fromDateFields(stopTime).toString("H:mm:ss"), fmt); tmpMeetTimeIntervals.add(new Interval(tmpStartDateTime, tmpStopDateTime)); } } return tmpMeetTimeIntervals; }
From source file:es.usc.citius.servando.calendula.drugdb.download.DBVersionManager.java
License:Open Source License
/** * Checks if there is any available update for the current medicine database. * * @param ctx the context/*from w ww .ja va 2s . c o m*/ * @return the version code of the update if there is one available, <code>null</code> otherwise */ public static String checkForUpdate(Context ctx) { final SharedPreferences prefs = PreferenceUtils.instance().preferences(); final String noneId = ctx.getString(R.string.database_none_id); final String database = prefs.getString(PreferenceKeys.DRUGDB_CURRENT_DB.key(), noneId); final String currentVersion = prefs.getString(PreferenceKeys.DRUGDB_VERSION.key(), null); if (!database.equals(noneId) && !database.equals(ctx.getString(R.string.database_setting_up))) { if (currentVersion != null) { final String lastDBVersion = DBVersionManager.getLastDBVersion(database); final DateTime lastDBDate = DateTime.parse(lastDBVersion, ISODateTimeFormat.basicDate()); final DateTime currentDBDate = DateTime.parse(currentVersion, ISODateTimeFormat.basicDate()); if (lastDBDate.isAfter(currentDBDate)) { LogUtil.d(TAG, "checkForUpdate: Update found for database " + database + " (" + lastDBVersion + ")"); return lastDBVersion; } else { LogUtil.d(TAG, "checkForUpdate: Database is updated. ID is '" + database + "', version is '" + currentVersion + "'"); return null; } } else { LogUtil.w(TAG, "checkForUpdate: Database is " + database + " but no version is set!"); return null; } } else { LogUtil.d(TAG, "checkForUpdate: No database. No version check needed."); return null; } }
From source file:eu.aylett.skyscanner.logparse.LineDetails.java
License:Apache License
static Optional<LineDetails> parseLogLine(String logLine) { Matcher matcher = pattern.matcher(logLine); if (!matcher.matches()) { LOG.error("Failed to match line: {}", logLine); return Optional.empty(); }// w ww.ja v a2 s.c o m DateTime timestamp; String timestampString = matcher.group(1); try { timestamp = DateTime.parse(timestampString, DATE_TIME_FORMATTER); } catch (DateTimeParseException e) { LOG.error("Failed to parse timestamp \"{}\" from {}", timestampString, logLine, e); return Optional.empty(); } String statusString = matcher.group(2); StatusClass status = statusString.startsWith("2") || statusString.startsWith("3") ? StatusClass.SUCCESS : StatusClass.FAILURE; long bytesTransferred; String bytesString = matcher.group(3); try { if (bytesString.equals("-")) { bytesTransferred = 0; } else { bytesTransferred = Long.parseLong(bytesString); } } catch (NumberFormatException e) { LOG.error("Failed to read number of bytes \"{}\" from {}", bytesString, logLine, e); return Optional.empty(); } long timeTaken; String timeString = matcher.group(4); try { timeTaken = Long.parseLong(timeString); } catch (NumberFormatException e) { LOG.error("Failed to read time taken \"{}\" from {}", timeString, logLine, e); return Optional.empty(); } return Optional.of(new LineDetails(timestamp, status, bytesTransferred, timeTaken)); }
From source file:eu.itesla_project.online.db.OnlineDbMVStore.java
License:Mozilla Public License
@Override public List<OnlineWorkflowDetails> listWorkflows(Interval basecaseInterval) { LOGGER.info("Getting list of stored workflows run on basecases within the interval {}", basecaseInterval); String dateFormatPattern = "yyyyMMdd_HHmm"; DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormatPattern); List<OnlineWorkflowDetails> workflowIds = new ArrayList<OnlineWorkflowDetails>(); File[] files = config.getOnlineDbDir().toFile().listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().startsWith(STORED_WORKFLOW_PREFIX); }/*from w w w. j a v a 2s. c o m*/ }); for (File file : files) { if (file.isFile()) { String workflowId = file.getName().substring(STORED_WORKFLOW_PREFIX.length()); if (workflowId.length() > dateFormatPattern.length() && workflowId .substring(dateFormatPattern.length(), dateFormatPattern.length() + 1).equals("_")) { String basecaseName = workflowId.substring(0, dateFormatPattern.length() - 1); DateTime basecaseDate = DateTime.parse(basecaseName, formatter); if (basecaseInterval.contains(basecaseDate.getMillis())) { OnlineWorkflowDetails workflowDetails = new OnlineWorkflowDetails(workflowId); workflowDetails.setWorkflowDate(getWorkflowDate(workflowId)); workflowIds.add(workflowDetails); } } } } Collections.sort(workflowIds, new Comparator<OnlineWorkflowDetails>() { @Override public int compare(OnlineWorkflowDetails wfDetails1, OnlineWorkflowDetails wfDetails2) { return wfDetails1.getWorkflowDate().compareTo(wfDetails2.getWorkflowDate()); } }); LOGGER.info("Found {} workflow(s)", workflowIds.size()); return workflowIds; }
From source file:eu.trentorise.opendata.jackan.ckan.CkanClient.java
License:Apache License
public static DateTime parseRevisionTimestamp(String revisionTimestamp) { checkNotEmpty(revisionTimestamp, "invalid ckan revision timestamp"); return DateTime.parse(revisionTimestamp, ISODateTimeFormat.dateHourMinuteSecond()); }
From source file:facebookpostpuller.PostModel.java
@Override public void run() { User friend;/*from w w w. ja v a 2 s . c om*/ User evaluatedFriend; DateTime birthdate; List<User> friends = myFriends.getData(); for (int i = this.startIndex; i < this.endIndex; i++) { if (stopped) { break; } friend = friends.get(i); // Start of Retry Try-Catch int count1 = 0; int maxTries = 5; while (true) { try { evaluatedFriend = facebookClient.fetchObject(friend.getId(), User.class, Parameter.with("fields", "id, name, birthday")); break; } catch (FacebookNetworkException ex) { System.err.println("Thread " + threadName + ": Retry #" + count1); outputString = "Thread " + threadName + ": Retry #" + count1 + "\n"; setChanged(); notifyObservers(); outputString = ""; if (++count1 == maxTries) { throw ex; } } } // End of Retry Try-Catch birthdate = new DateTime(evaluatedFriend.getBirthdayAsDate()); // This line checks if the user's profile has his/her birthdate set and made public // Skips users who has no bday set and made public on their profile if (birthdate.getYear() == DateTime.now().getYear()) { PostModel.progress++; setChanged(); notifyObservers(); continue; } // DELETE MO TOOOOOOO int age = calculateAge(evaluatedFriend.getBirthdayAsDate()); if (age >= 13 && age <= 17 && !check[0]) { PostModel.progress++; setChanged(); notifyObservers(); continue; } else if (age >= 18 && age <= 24 && !check[1]) { PostModel.progress++; setChanged(); notifyObservers(); continue; } else if (age >= 25 && age <= 34 && !check[2]) { PostModel.progress++; setChanged(); notifyObservers(); continue; } else if (age >= 35 && age <= 44 && !check[3]) { PostModel.progress++; setChanged(); notifyObservers(); continue; } else if (age >= 45 && !check[4]) { // Modified 6/11/2014 PostModel.progress++; setChanged(); notifyObservers(); continue; } // END OF DELETE MO TOOOOOOO //outputString = "Thread " + threadName + "\n" // + "Name: " // + evaluatedFriend.getName() // + "\nAge: " // + calculateAge(evaluatedFriend.getBirthdayAsDate()) + "\n\n"; //setChanged(); //notifyObservers(); outputString = ""; DateTime minusOneYear = DateTime .parse(evaluatedFriend.getBirthday(), DateTimeFormat.forPattern("M/d/y")) .withYear(DateTime.now().getYear()).minusYears(1); Long targetTime = minusOneYear.getMillis() / 1000; Long now = DateTime.now().getMillis() / 1000; System.out.println("Thread " + threadName + ": " + evaluatedFriend.getName()); Connection<Post> feed = null; // Start of Retry Try-Catch int count2 = 0; while (true) { try { if (calculateAge(evaluatedFriend.getBirthdayAsDate()) >= 18 && calculateAge(evaluatedFriend.getBirthdayAsDate()) <= 24) { feed = facebookClient.fetchConnection(evaluatedFriend.getId().concat("/posts"), Post.class, Parameter.with("fields", "message,from"), Parameter.with("until", now), Parameter.with("since", targetTime), Parameter.with("limit", 50)); // limited to x posts // Dataset range (first x posts since the user's birthdate last year until today) } else { feed = facebookClient.fetchConnection(evaluatedFriend.getId().concat("/posts"), Post.class, Parameter.with("fields", "message,from"), Parameter.with("limit", 500)); // limited to x posts } break; } catch (FacebookNetworkException ex) { System.err.println("Thread " + threadName + ": Retry #" + count2); outputString = "Thread " + threadName + ": Retry #" + count2 + "\n"; setChanged(); notifyObservers(); outputString = ""; if (++count2 == maxTries) { throw ex; } } } // End of Retry Try-Catch String recentMessage = ""; boolean userHasPosts = false; for (Post post : feed.getData()) { if (stopped) { break; } if (post.getMessage() == null) { continue; } // Prevents duplicate posts. Idk kung bug ba ng RestFB o kung ano man if (recentMessage.equals(post.getMessage())) { recentMessage = post.getMessage(); continue; } recentMessage = post.getMessage(); // End of duplicate checker //outputString = post.getMessage() + "\n"; //setChanged(); //notifyObservers(); //outputString = ""; posts.put(post, evaluatedFriend); userHasPosts = true; } if (userHasPosts) { // Puts the name and age of the friend metadata.put(String.valueOf(evaluatedFriend.getName()), String.valueOf(calculateAge(evaluatedFriend.getBirthdayAsDate()))); } PostModel.progress++; setChanged(); notifyObservers(); } stopped = true; System.out.println("Thread " + threadName + " finished execution\n" + posts.size()); System.out.println(metadata.size()); }
From source file:facebookpostpuller.PostModelBACKUP.java
@Override public void run() { User friend;/* w w w . j a v a2 s .co m*/ User evaluatedFriend; DateTime birthdate; List<User> friends = myFriends.getData(); for (int i = this.startIndex; i < this.endIndex; i++) { if (stopped) { break; } friend = friends.get(i); evaluatedFriend = facebookClient.fetchObject(friend.getId(), User.class, Parameter.with("fields", "id, name, birthday")); birthdate = new DateTime(evaluatedFriend.getBirthdayAsDate()); // This line checks if the user's profile has his/her birthdate set and made public // Skips users who has no bday set and made public on their profile if (birthdate.getYear() == DateTime.now().getYear()) { continue; } // Puts the name and age of the friend metadata.put(String.valueOf(evaluatedFriend.getName()), String.valueOf(calculateAge(evaluatedFriend.getBirthdayAsDate()))); outputString = "Thread " + threadName + "\n" + "Name: " + evaluatedFriend.getName() + "\nAge: " + calculateAge(evaluatedFriend.getBirthdayAsDate()) + "\n\n"; setChanged(); notifyObservers(); outputString = ""; DateTime minusOneYear = DateTime .parse(evaluatedFriend.getBirthday(), DateTimeFormat.forPattern("M/d/y")) .withYear(DateTime.now().getYear()).minusYears(1); Long targetTime = minusOneYear.getMillis() / 1000; Long now = DateTime.now().getMillis() / 1000; System.out.println("Thread " + threadName + ": " + evaluatedFriend.getName()); Connection<Post> feed = facebookClient.fetchConnection(evaluatedFriend.getId().concat("/posts"), Post.class, Parameter.with("fields", "message,from"), Parameter.with("until", now), Parameter.with("since", targetTime), Parameter.with("limit", 200)); // limited to x posts // Dataset range (first x posts since the user's birthdate last year until today) String recentMessage = ""; for (Post post : feed.getData()) { if (stopped) { break; } if (post.getMessage() == null) { continue; } // Prevents duplicate posts. Idk kung bug ba ng RestFB o kung ano man if (recentMessage.equals(post.getMessage())) { recentMessage = post.getMessage(); continue; } recentMessage = post.getMessage(); // End of duplicate checker //outputString = post.getMessage() + "\n"; //setChanged(); //notifyObservers(); //outputString = ""; posts.put(post, evaluatedFriend); } } stopped = true; System.out.println("Thread " + threadName + " finished execution\n" + posts.size()); System.out.println(metadata.size()); }
From source file:facebookpostpuller.PostModelBACKUP2.java
@Override public void run() { User friend;/*from w ww.j av a2 s . c o m*/ User evaluatedFriend; DateTime birthdate; List<User> friends = myFriends.getData(); for (int i = this.startIndex; i < this.endIndex; i++) { if (stopped) { break; } friend = friends.get(i); // Start of Retry Try-Catch int count1 = 0; int maxTries = 5; while (true) { try { evaluatedFriend = facebookClient.fetchObject(friend.getId(), User.class, Parameter.with("fields", "id, name, birthday")); break; } catch (FacebookNetworkException ex) { System.err.println( "Thread " + threadName + " encountered an error. Retrying... Retry #" + count1); outputString = "Thread " + threadName + " encountered an error. Retrying... Retry #" + count1 + "\n"; setChanged(); notifyObservers(); outputString = ""; if (++count1 == maxTries) { throw ex; } } } // End of Retry Try-Catch birthdate = new DateTime(evaluatedFriend.getBirthdayAsDate()); // This line checks if the user's profile has his/her birthdate set and made public // Skips users who has no bday set and made public on their profile if (birthdate.getYear() == DateTime.now().getYear()) { PostModelBACKUP2.progress++; setChanged(); notifyObservers(); continue; } //outputString = "Thread " + threadName + "\n" // + "Name: " // + evaluatedFriend.getName() // + "\nAge: " // + calculateAge(evaluatedFriend.getBirthdayAsDate()) + "\n\n"; //setChanged(); //notifyObservers(); //outputString = ""; DateTime minusOneYear = DateTime .parse(evaluatedFriend.getBirthday(), DateTimeFormat.forPattern("M/d/y")) .withYear(DateTime.now().getYear()).minusYears(1); Long targetTime = minusOneYear.getMillis() / 1000; Long now = DateTime.now().getMillis() / 1000; System.out.println("Thread " + threadName + ": " + evaluatedFriend.getName()); Connection<Post> feed = null; // Start of Retry Try-Catch int count2 = 0; while (true) { try { if (calculateAge(evaluatedFriend.getBirthdayAsDate()) >= 18 && calculateAge(evaluatedFriend.getBirthdayAsDate()) <= 24) { feed = facebookClient.fetchConnection(evaluatedFriend.getId().concat("/posts"), Post.class, Parameter.with("fields", "message,from"), Parameter.with("until", now), Parameter.with("since", targetTime), Parameter.with("limit", 50)); // limited to x posts // Dataset range (first x posts since the user's birthdate last year until today) } else { feed = facebookClient.fetchConnection(evaluatedFriend.getId().concat("/posts"), Post.class, Parameter.with("fields", "message,from"), Parameter.with("limit", 500)); // limited to x posts // Dataset range (first x posts since the user's birthdate last year until today) } break; } catch (FacebookNetworkException ex) { System.err.println( "Thread " + threadName + " encountered an error. Retrying... Retry #" + count2); outputString = "Thread " + threadName + " encountered an error. Retrying... Retry #" + count2 + "\n"; setChanged(); notifyObservers(); outputString = ""; if (++count2 == maxTries) { throw ex; } } } // End of Retry Try-Catch String recentMessage = ""; boolean userHasPosts = false; for (Post post : feed.getData()) { if (stopped) { break; } if (post.getMessage() == null) { continue; } // Prevents duplicate posts. Idk kung bug ba ng RestFB o kung ano man if (recentMessage.equals(post.getMessage())) { recentMessage = post.getMessage(); continue; } recentMessage = post.getMessage(); // End of duplicate checker //outputString = post.getMessage() + "\n"; //setChanged(); //notifyObservers(); //outputString = ""; posts.put(post, evaluatedFriend); userHasPosts = true; } if (userHasPosts) { // Puts the name and age of the friend metadata.put(String.valueOf(evaluatedFriend.getName()), String.valueOf(calculateAge(evaluatedFriend.getBirthdayAsDate()))); } PostModelBACKUP2.progress++; setChanged(); notifyObservers(); } stopped = true; System.out.println("Thread " + threadName + " finished execution\n" + posts.size()); System.out.println(metadata.size()); }
From source file:google.registry.tools.params.DateParameter.java
License:Open Source License
@Override public DateTime convert(String value) { return DateTime.parse(value, STRICT_DATE_PARSER).withZoneRetainFields(UTC); }
From source file:google.registry.tools.params.DateTimeParameter.java
License:Open Source License
@Override public DateTime convert(String value) { Long millis = Longs.tryParse(value); if (millis != null) { return new DateTime(millis.longValue(), UTC); }/* w w w. j av a2 s. c o m*/ return DateTime.parse(value, STRICT_DATE_TIME_PARSER).withZone(UTC); }