List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
License:Open Source License
void addMonthlyReportUrls(PrintWriter pw, int numMonthlyReports, String metricsServiceUrl) { DateTime input = newDateTime();//from w w w . ja v a2s. co m LOGGER.debug("NOW: {}", input); for (int i = 1; i <= numMonthlyReports; i++) { try { DateMidnight startOfLastMonth = new DateMidnight(input.minusMonths(i).withDayOfMonth(1)); String startDate = urlEncodeDate(startOfLastMonth); LOGGER.debug("Previous Month (start): {} (ms = {})", startDate, startOfLastMonth.getMillis()); DateTime endOfLastMonth = startOfLastMonth.plusMonths(1).toDateTime().minus(1 /* millisecond */); String endDate = urlEncodeDate(endOfLastMonth); LOGGER.debug("Previous Month (end): {} (ms = {})", endOfLastMonth, endOfLastMonth.getMillis()); startTableRow(pw, i); addCellLabelForRange(pw, startOfLastMonth, endOfLastMonth); addXLSCellLink(pw, startDate, endDate, metricsServiceUrl); addPPTCellLink(pw, startDate, endDate, metricsServiceUrl); endTableRow(pw); } catch (UnsupportedEncodingException e) { LOGGER.info("Unsupported encoding exception adding monthly reports", e); } } }
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
License:Open Source License
void addYearlyReportUrls(PrintWriter pw, int numYearlyReports, String metricsServiceUrl) { DateTime input = newDateTime();// w ww . j a v a2s. com LOGGER.debug("NOW: {}", input); for (int i = 1; i <= numYearlyReports; i++) { try { DateMidnight startOfLastYear = new DateMidnight(input.minusYears(1).withDayOfYear(1)); String startDate = urlEncodeDate(startOfLastYear); LOGGER.debug("Previous Year (start): {} (ms = {})", startOfLastYear, startOfLastYear.getMillis()); DateTime endOfLastYear = startOfLastYear.plusYears(1).toDateTime().minus(1 /* millisecond */); String endDate = urlEncodeDate(endOfLastYear); LOGGER.debug("Previous Year (end): {}, (ms = {})", endOfLastYear, endOfLastYear.getMillis()); String urlText = startOfLastYear.toString("yyyy"); LOGGER.debug("URL text = [{}]", urlText); startTableRow(pw, i); addCellLabel(pw, urlText); addXLSCellLink(pw, startDate, endDate, metricsServiceUrl); addPPTCellLink(pw, startDate, endDate, metricsServiceUrl); endTableRow(pw); } catch (UnsupportedEncodingException e) { LOGGER.info("Unsupported encoding exception adding yearly reports", e); } } }
From source file:ddf.security.samlp.impl.SamlValidator.java
License:Open Source License
protected void checkTimestamp() throws ValidationException { DateTime issueInstant = getIssueInstant(); if (issueInstant == null) { throw new ValidationException("Issue Instant cannot be null!"); }// ww w. j a v a 2 s .c o m Instant instant = Instant.ofEpochMilli(issueInstant.getMillis()); Instant now = Instant.now(); if (instant.minus(builder.clockSkew).isAfter(now)) { throw new ValidationException("Issue Instant cannot be in the future"); } if (instant.plus(builder.clockSkew).isBefore(now.minus(builder.timeout))) { throw new ValidationException("Issue Instant was outside valid time range"); } }
From source file:de.azapps.mirakel.helper.DateTimeHelper.java
License:Open Source License
private static CharSequence getRelativeDate(final Context ctx, final DateTime date, final boolean reminder) { final DateTime now = new LocalDate().toDateTimeAtStartOfDay(); if ((Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) || !(now.isBefore(date) && now.plusDays(1).isAfter(date)) || reminder) { return DateUtils.getRelativeTimeSpanString(date.getMillis(), new Date().getTime(), reminder ? DateUtils.MINUTE_IN_MILLIS : DateUtils.DAY_IN_MILLIS); }/*from www . j a va 2s. c om*/ return ctx.getString(R.string.today); }
From source file:de.azapps.mirakel.model.list.meta.SpecialListsDueProperty.java
License:Open Source License
@NonNull @Override/*from www .ja v a2 s .c o m*/ public MirakelQueryBuilder getWhereQueryBuilder(@NonNull final Context ctx) { MirakelQueryBuilder qb = new MirakelQueryBuilder(ctx).and(Task.DUE, MirakelQueryBuilder.Operation.NOT_EQ, (String) null); DateTime date = new LocalDate().toDateTimeAtStartOfDay().plusDays(1).minusSeconds(10); Log.w(TAG, String.valueOf(date.getMillis())); switch (unit) { case DAY: date = date.plusDays(length); break; case MONTH: date = date.plusMonths(length); break; case YEAR: date = date.plusYears(length); break; } qb = qb.and(Task.DUE, isSet ? Operation.GT : Operation.LT, date.getMillis()); Log.w(TAG, qb.toString(Task.URI)); return qb; }
From source file:de.azapps.mirakel.model.recurring.Recurring.java
License:Open Source License
@NonNull public Task incrementRecurringDue(final Task t) { if (!t.getDue().isPresent()) { return t; }/*from w w w. j a v a2 s. c om*/ final DateTime newDue = addRecurring(of(new DateTime(t.getDue().get())), true).get(); if (newDue.compareTo(t.getDue().get()) == 0) { return t; } return new MirakelQueryBuilder(context).select(allTWColumns).and(CHILD, Operation.EQ, t) .query(MirakelInternalContentProvider.RECURRING_TW_URI) .doWithCursor(new CursorWrapper.CursorConverter<Task>() { @Override public Task convert(@NonNull CursorGetter getter) { long masterID = t.getId(); long offset = 0L; long offsetCount = 0L; if (getter.moveToFirst()) {// this is already a child-task masterID = getter.getLong(PARENT); offset = getter.getLong(OFFSET); offsetCount = getter.getLong(OFFSET_COUNT); } offset += newDue.getMillis() - t.getDue().get().getMillis(); ++offsetCount; Optional<Task> child = new MirakelQueryBuilder(context).select(CHILD) .and(PARENT, Operation.EQ, masterID).and(OFFSET_COUNT, Operation.EQ, offsetCount) .query(MirakelInternalContentProvider.RECURRING_TW_URI) .doWithCursor(new CursorWrapper.CursorConverter<Optional<Task>>() { @Override public Optional<Task> convert(@NonNull final CursorGetter getter) { if (getter.moveToFirst()) { return Task.get(getter.getLong(0)); } return absent(); } }); if (child.isPresent()) { return child.get(); } t.setDue(of(newDue)); final Task newTask; try { newTask = t.create(); } catch (final NoSuchListException e) { Log.wtf(TAG, "list vanished", e); ErrorReporter.report(ErrorType.LIST_VANISHED); return t; } ContentValues cv = new ContentValues(); cv.put(Task.RECURRING, t.getRecurrenceId()); cv.put(Task.UUID, UUID.randomUUID().toString()); cv.put(DatabaseHelper.SYNC_STATE_FIELD, SYNC_STATE.ADD.toInt()); update(MirakelInternalContentProvider.TASK_URI, cv, ModelBase.ID + "=?", new String[] { String.valueOf(newTask.getId()) }); cv = new ContentValues(); cv.put(PARENT, masterID); cv.put(CHILD, newTask.getId()); cv.put(OFFSET, offset); cv.put(OFFSET_COUNT, offsetCount); insert(MirakelInternalContentProvider.RECURRING_TW_URI, cv); return newTask; } }); }
From source file:de.cinovo.cloudconductor.server.rest.impl.AgentImpl.java
License:Apache License
@Override @Transactional//from w w w. j a va 2 s .c o m public PackageStateChanges notifyPackageState(String tname, String hname, PackageState rpmState, String huuid) { RESTAssert.assertNotEmpty(hname); RESTAssert.assertNotEmpty(tname); EHost host = this.dhost.findByUuid(huuid); if (host == null) { host = this.createNewHost(hname, this.dtemplate.findByName(tname)); } ETemplate template = this.dtemplate.findByName(tname); RESTAssert.assertNotNull(template); DateTime now = new DateTime(); host.setLastSeen(now.getMillis()); List<EPackage> packages = this.dpkg.findList(); HashSet<EPackageState> leftPackages = new HashSet<>(host.getPackages()); for (PackageVersion irpm : rpmState.getInstalledRpms()) { EPackage pkg = null; for (EPackage p : packages) { if (p.getName().equals(irpm.getName())) { pkg = p; break; } } if (pkg == null) { continue; } EPackageState state = this.updateExistingState(host, irpm, leftPackages); if (state == null) { state = this.createMissingState(host, irpm, pkg); host.getPackages().add(state); } } for (EPackageState pkg : leftPackages) { if (host.getPackages().contains(pkg)) { host.getPackages().remove(pkg); this.dpkgstate.delete(pkg); } } host = this.dhost.save(host); // check whether the host may update or has to wait for another host to finish updateing if (this.sendPackageChanges(template, host)) { // Compute instruction lists (install/update/erase) from difference between packages actually installed packages that should be // installed. Set<EPackageVersion> actual = new HashSet<>(); for (EPackageState state : host.getPackages()) { actual.add(state.getVersion()); } ArrayListMultimap<PackageCommand, PackageVersion> diff = this .computePackageDiff(template.getPackageVersions(), actual); if (!diff.get(PackageCommand.INSTALL).isEmpty() || !diff.get(PackageCommand.UPDATE).isEmpty() || !diff.get(PackageCommand.ERASE).isEmpty()) { host.setStartedUpdate(DateTime.now().getMillis()); } return new PackageStateChanges(diff.get(PackageCommand.INSTALL), diff.get(PackageCommand.UPDATE), diff.get(PackageCommand.ERASE)); } return new PackageStateChanges(new ArrayList<PackageVersion>(), new ArrayList<PackageVersion>(), new ArrayList<PackageVersion>()); }
From source file:de.cinovo.cloudconductor.server.rest.impl.AgentImpl.java
License:Apache License
@Override @Transactional// www . j a v a 2 s .c o m public AgentOptions heartBeat(String tname, String hname, String agentN, String huuid) { RESTAssert.assertNotEmpty(hname); RESTAssert.assertNotEmpty(tname); RESTAssert.assertNotEmpty(agentN); RESTAssert.assertNotEmpty(huuid); EAgent agent = this.dAgent.findAgentByName(agentN); if (agent == null) { agent = this.createNewAgent(agentN, null); } EHost host = this.dhost.findByUuid(huuid); if (host == null) { host = this.createNewHost(hname, this.dtemplate.findByName(tname)); } if (host == null) { host = this.createNewHost(hname, this.dtemplate.findByName(tname)); String uuid = UUID.randomUUID().toString(); host.setUuid(uuid); } DateTime now = new DateTime(); host.setLastSeen(now.getMillis()); host.setAgent(agent); host = this.dhost.save(host); EAgentOption options = this.dagentoptions.findByTemplate(host.getTemplate()); if (options == null) { options = new EAgentOption(); options.setTemplate(host.getTemplate()); options = this.dagentoptions.save(options); } AgentOptions result = MAConverter.fromModel(options); result.setTemplateName(host.getTemplate().getName()); boolean onceExecuted = false; if (options.getDoSshKeys() == TaskState.ONCE) { if (host.getExecutedSSH()) { result.setDoSshKeys(TaskState.OFF); } else { onceExecuted = true; host.setExecutedSSH(true); } } if (options.getDoPackageManagement() == TaskState.ONCE) { if (host.getExecutedPkg()) { result.setDoPackageManagement(TaskState.OFF); } else { onceExecuted = true; host.setExecutedPkg(true); } } if (options.getDoFileManagement() == TaskState.ONCE) { if (host.getExecutedFiles()) { result.setDoFileManagement(TaskState.OFF); } else { onceExecuted = true; host.setExecutedFiles(true); } } if (onceExecuted) { this.dhost.save(host); } result.setUuid(host.getUuid()); return result; }
From source file:de.codesourcery.threadwatcher.HiResTimestamp.java
License:Apache License
public HiResTimestamp(DateTime dt, boolean truncatedToMillis) { this(dt.getMillis() / 1000, (dt.getMillis() - (dt.getMillis() / 1000) * 1000) * 1000000, truncatedToMillis); }
From source file:de.dmarcini.submatix.android4.full.gui.SPX42ReadLogFragment.java
License:Open Source License
/** * // www. ja v a 2s.c o m * Bearbeite die Nachricht ber einen Logeintrag * * Project: SubmatixBTLoggerAndroid_4 Package: de.dmarcini.submatix.android4.gui * * * Stand: 06.08.2013 * * @param msg */ private void msgComputeDirentry( BtServiceMessage msg ) { // Fields // 0 => Nummer // 1 => Filename // 2 => Max Nummer String[] fields; String fileName; int dbId = -1; String detailText; int number, max; int day, month, year, hour, minute, second; boolean isSaved = false; Resources res = runningActivity.getResources(); // if( !( msg.getContainer() instanceof String[] ) ) { Log.e( TAG, "Message container not an String ARRAY!" ); return; } fields = ( String[] )msg.getContainer(); if( fields.length < 3 ) { Log.e( TAG, "recived message for logdir has lower than 3 fields. It is wrong! Abort!" ); return; } // Wandel die Nummerierung in Integer um try { number = Integer.parseInt( fields[0], 16 ); max = Integer.parseInt( fields[2], 16 ); } catch( NumberFormatException ex ) { Log.e( TAG, "Fail to convert Hex to int: " + ex.getLocalizedMessage() ); return; } // Alles gelesen: Fertich if( number == max ) { countDirEntrys = 0; if( pd != null ) { pd.dismiss(); } return; } fileName = fields[1]; // verwandle die Dateiangabe in eine lesbare Datumsangabe // Format des Strings ist ja // TAG_MONAT_JAHR_STUNDE_MINUTE_SEKUNDE // des Beginns der Aufzeichnung fields = fieldPatternUnderln.split( fields[1] ); try { day = Integer.parseInt( fields[0] ); month = Integer.parseInt( fields[1] ); year = Integer.parseInt( fields[2] ) + 2000; hour = Integer.parseInt( fields[3] ); minute = Integer.parseInt( fields[4] ); second = Integer.parseInt( fields[5] ); } catch( NumberFormatException ex ) { Log.e( TAG, "Fail to convert Hex to int: " + ex.getLocalizedMessage() ); return; } // So, die Angaben des SPX sind immer im Localtime-Format // daher werde ich die auch so interpretieren // Die Funktion macht das in der default-Lokalzone, sollte also // da sein, wo der SPX auch ist... (schwieriges Thema) DateTime tm = new DateTime( year, month, day, hour, minute, second ); // // Jetzt ist der Zeitpunkt, die Datenbank zu befragen, ob das Logteilchen schon gesichert ist // isSaved = logManager.isLogInDatabase( FragmentCommonActivity.spxConfig.getSerial(), fileName ); if( isSaved ) { if( showAllLogEntrys ) { SPX42DiveHeadData diveHead = logManager.getDiveHeader( FragmentCommonActivity.spxConfig.getSerial(), fileName ); detailText = makeDetailText( diveHead ); dbId = diveHead.diveId; // // jetzt eintagen in die Anzeige // ReadLogItemObj rlio = new ReadLogItemObj( isSaved, String.format( "#%03d: %s", number, tm.toString( FragmentCommonActivity.localTimeFormatter ) ), fileName, detailText, dbId, number, tm.getMillis() ); // Eintrag an den Anfang stellen logListAdapter.insert( rlio, 0 ); } else { if( ApplicationDEBUG.DEBUG ) Log.i( TAG, "ignore saved log while \"show all logitems\" is not set..." ); } } else { detailText = res.getString( R.string.logread_not_saved_yet_msg ); // // jetzt eintagen in die Anzeige // ReadLogItemObj rlio = new ReadLogItemObj( isSaved, String.format( "#%03d: %s", number, tm.toString( FragmentCommonActivity.localTimeFormatter ) ), fileName, detailText, dbId, number, tm.getMillis() ); // Eintrag an den Anfang stellen logListAdapter.insert( rlio, 0 ); } if( pd != null ) { pd.setMessage( String.format( runningActivity.getResources().getString( R.string.logread_please_wait_dialog_directory ), ++countDirEntrys ) ); } }