List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.blackducksoftware.integration.jira.task.JiraSettingsService.java
License:Apache License
public static List<TicketCreationError> expireOldErrors(final PluginSettings pluginSettings) { logger.debug("Pulling error messages from settings"); final Object errorObject = pluginSettings.get(HubJiraConstants.HUB_JIRA_ERROR); if (errorObject == null) { logger.debug("No error messages found in settings"); return null; }/* ww w.j ava2 s.c om*/ if (!(errorObject instanceof String)) { logger.warn( "The error object in settings is invalid (probably stored by an older version of the plugin); discarding it"); pluginSettings.remove(HubJiraConstants.HUB_JIRA_ERROR); return null; } List<TicketCreationError> ticketErrors = null; final String ticketErrorsString = (String) errorObject; try { ticketErrors = TicketCreationError.fromJson(ticketErrorsString); } catch (final Exception e) { logger.warn("Error deserializing JSON string pulled from settings: " + e.getMessage() + "; resettting error message list"); pluginSettings.remove(HubJiraConstants.HUB_JIRA_ERROR); return null; } if ((ticketErrors == null) || ticketErrors.isEmpty()) { logger.debug("No error messages found in settings"); return null; } logger.debug("# error messages pulled from settings: " + ticketErrors.size()); Collections.sort(ticketErrors); final DateTime currentTime = DateTime.now(); final Iterator<TicketCreationError> expirationIterator = ticketErrors.iterator(); while (expirationIterator.hasNext()) { final TicketCreationError ticketError = expirationIterator.next(); final DateTime errorTime = ticketError.getTimeStampDateTime(); if (Days.daysBetween(errorTime, currentTime).isGreaterThan(Days.days(30))) { logger.debug("Removing old error message with timestamp: " + ticketError.getTimeStamp()); expirationIterator.remove(); } } logger.debug("Saving " + ticketErrors.size() + " non-expired error messages in settings"); pluginSettings.put(HubJiraConstants.HUB_JIRA_ERROR, TicketCreationError.toJson(ticketErrors)); return ticketErrors; }
From source file:com.boha.vodacom.util.PoliceStationLoader.java
private Date getDate() { DateTime dt = DateTime.now(); int days = random.nextInt(6); DateTime then = dt.minusDays(days); return then.toDate(); }
From source file:com.brewtab.irclog.SQLFromIrssiLog.java
License:Open Source License
private void run() throws Exception { if (channel == null) { Matcher channelMatcher = Pattern.compile("^(?:.*/)?(.*)\\.log$").matcher(logFile); if (channelMatcher.matches()) { channel = channelMatcher.group(1); } else {/*from www . jav a2s . c om*/ throw new IllegalArgumentException("Could not determine channel from log file name"); } } input = new BufferedReader(new FileReader(logFile)); currentDate = DateTime.now(); System.out.println("BEGIN;"); while (true) { String line = input.readLine(); if (line == null) { break; } try { processLine(line); } catch (Exception e) { log.error("Error on line: {}", line, e); break; } } System.out.println("COMMIT;"); input.close(); }
From source file:com.buabook.exacttarget.fuelsdk.AutoRefreshETClient.java
License:GNU General Public License
/** * Performs the standard {@link ETClient#refreshToken()} with the added refresh of the refresh token if * it has been greater than the specified duration ({@link #refreshTokenLife}) since the last refresh. *///from www .j a v a 2 s . c o m @Override public synchronized String refreshToken() throws ETSdkException { if (lastRefreshTime != null && lastRefreshTime.plus(refreshTokenLife).isBeforeNow()) { log.info("Refreshing refresh token after configured duration"); lastRefreshTime = DateTime.now(); requestToken(null); } return super.refreshToken(); }
From source file:com.buabook.exacttarget.fuelsdk.AutoRefreshETClient.java
License:GNU General Public License
private void initialiseRefreshTracking(Duration refreshTokenLife) throws IllegalArgumentException { if (refreshTokenLife == null || refreshTokenLife.isEqual(Duration.ZERO)) throw new IllegalArgumentException("Invalid refresh token life duration"); this.refreshTokenLife = refreshTokenLife; this.lastRefreshTime = DateTime.now(); log.info("ExactTarget client with auto-refresh of refresh token created [ Refresh Duration: " + refreshTokenLife + " ]"); }
From source file:com.bytestemplar.subgeniuswatchface.BT_SubgeniusWatchface.java
License:Apache License
private String getXDayCountdown() { DateTime today = DateTime.now(); //DateTime today = new DateTime( 1998, 7, 6, 4, 20, 32, 0 ); DateTime xday = new DateTime(today.getYear(), 7, 5, 7, 0, 0, 0); if (today.isAfter(xday)) { xday = new DateTime(today.getYear() + 1, 7, 5, 7, 0, 0, 0); }/*ww w . ja v a 2 s .c o m*/ Duration dur = new Duration(today, xday); StringBuilder sb = new StringBuilder(); if (dur.getStandardDays() > 0) { sb.append(dur.getStandardDays()); sb.append(" Day"); if (dur.getStandardDays() > 1) { sb.append("s"); } sb.append("\n"); } long hours = dur.getStandardHours() % 24; if (hours > 0) { sb.append(hours); sb.append(" Hour"); if (hours > 1) { sb.append("s"); } sb.append("\n"); } long mins = dur.getStandardMinutes() % 60; if (mins > 0) { sb.append(mins); sb.append(" Minute"); if (mins > 1) { sb.append("s"); } sb.append("\n"); } long secs = dur.getStandardSeconds() % 60; if (secs > 0) { sb.append(secs); sb.append(" Second"); if (secs > 1) { sb.append("s"); } sb.append("\n"); } sb.append("Until X-Day!"); return sb.toString(); }
From source file:com.cenrise.test.azkaban.Utils.java
License:Apache License
public static String formatDuration(final long startTime, final long endTime) { if (startTime == -1) { return "-"; }/*from w ww.ja v a 2 s . c o m*/ final long durationMS; if (endTime == -1) { durationMS = DateTime.now().getMillis() - startTime; } else { durationMS = endTime - startTime; } long seconds = durationMS / 1000; if (seconds < 60) { return seconds + " sec"; } long minutes = seconds / 60; seconds %= 60; if (minutes < 60) { return minutes + "m " + seconds + "s"; } long hours = minutes / 60; minutes %= 60; if (hours < 24) { return hours + "h " + minutes + "m " + seconds + "s"; } final long days = hours / 24; hours %= 24; return days + "d " + hours + "h " + minutes + "m"; }
From source file:com.cfap.cfadevicemanager.models.TrafficSnapshot.java
License:Apache License
private TrafficSnapshot(Context context) { apps = new HashMap<>(); for (ApplicationInfo app : context.getPackageManager().getInstalledApplications(0)) { apps.put(app.uid, new AppTrafficSnapshot(app.uid, app.packageName, app.icon)); }/*ww w. j av a 2 s . c o m*/ timeStamp = DateTime.now(); }
From source file:com.chessix.vas.actors.JournalActor.java
License:Apache License
/** * Update the time delay between creation of the message and processing it. *///from www . jav a 2 s .co m private void updateTimeDelay(final Date timestamp) { final Duration d = new Interval(new DateTime(timestamp), DateTime.now()).toDuration(); if ((delay == null) || (d.compareTo(delay) > 0)) { delay = d; } }
From source file:com.citrix.g2w.webdriver.flows.Session.java
License:Open Source License
/** * Method to add attendee to a session//from ww w.j av a2 s . co m * * @param webinarId * Webinar Id * @param registrationId * Registration ID of the attendee * @param email * Attendee email * @param name * Attendee name * @param joinTime * Attendee join time * @param leaveTime * Attendee leave time */ public void addAttendee(final Long webinarId, final Long registrationId, final String email, final String name, DateTime joinTime, DateTime leaveTime) { RpcResponse rpcResponse = this.endpoint.joinWebinar(null, registrationId, webinarId); try { this.exitPopUpUrl = rpcResponse.getParams().getString("ExitPopUpUrl"); } catch (Exception e) { // no operation } if (joinTime == null) { joinTime = DateTime.now(); } WebinarSession session = this.sessions.get(webinarId); int participantId = session.addAttendee(email, name, joinTime, leaveTime); this.endpoint.addAttendeeInfo(webinarId, participantId, email, name); }