Example usage for org.joda.time DateTime getMillis

List of usage examples for org.joda.time DateTime getMillis

Introduction

In this page you can find the example usage for org.joda.time DateTime getMillis.

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:com.tkmtwo.sarapi.convert.DateTimeToValueConverter.java

License:Apache License

@Override
public Value convert(DateTime dt) {
    if (dt == null) {
        return new Value();
    }/*from  ww  w.j av a2s .c o  m*/
    Timestamp t = new Timestamp(dt.getMillis() / 1000L);
    return new Value(t);
}

From source file:com.tkmtwo.sarapi.mapping.MappingSetEntry.java

License:Apache License

public void setEntry(Entry entry, DateTime dt, int nOption) {

    checkArgument(entry != null, "Entry is null");
    checkArgument(entry.getEntryId() != null, "Entry ID is null");

    ///*from  w  w  w  .  j a va 2  s . c  o m*/
    // When setting and entry, if we allow column 1 in the entry, the API will complain with:
    // WARNING (52): The field is a core system field and cannot be changed; 1
    //
    // So...we remove it here after we pull it out into a String for use later
    //

    String entryId = entry.getEntryId();
    entry.remove(Integer.valueOf(1));

    for (EntryHandler eh : getEntryHandlers()) {
        eh.handleEntry(entry);
    }

    getTemplate().setEntry(getFormName(), entryId, entry, new Timestamp(dt.getMillis() / 1000L), nOption);
}

From source file:com.tkmtwo.sarapi.support.ValueUtil.java

License:Apache License

public static Timestamp toTimestamp(DateTime dt) {
    if (dt == null) {
        return null;
    }/* w  w  w.j  a  v a 2s  . c  o  m*/

    return new Timestamp(dt.getMillis() / 1000L);
}

From source file:com.tkmtwo.sarapi.support.ValueUtil.java

License:Apache License

public static Value valueOf(DateTime dt) {
    return (dt == null) ? new Value() : new Value(new Timestamp(dt.getMillis() / 1000L));
}

From source file:com.tkmtwo.timex.ibatis.DateTimeLongMillisTypeHandler.java

License:Apache License

@Override
public void setNonNullParameter(PreparedStatement ps, int i, DateTime parameter, JdbcType jdbcType)
        throws SQLException {

    long dtMillis = parameter.getMillis();
    logger.debug("Setting non-null DateTime parameter {} to {}.", DateTimes.printExtended(parameter),
            String.valueOf(dtMillis));

    ps.setLong(i, parameter.getMillis());
}

From source file:com.todoroo.andlib.utility.DateUtilities.java

License:Open Source License

/**
 * Add the specified amount of months to the given time.<br/>
 * The day of month will stay the same.<br/>
 *
 * @param time the base-time (in milliseconds) to which the amount of months is added
 * @param interval the amount of months to be added
 * @return the calculated time in milliseconds
 *//*from  w w w  .j av a 2s .c  o  m*/
public static long addCalendarMonthsToUnixtime(long time, int interval) {
    DateTime dt = new DateTime(time);
    DateTime result = dt.plusMonths(interval);
    // preserving java.util.date behavior
    int diff = dt.getDayOfMonth() - result.getDayOfMonth();
    if (diff > 0) {
        result = result.plusDays(diff);
    }
    return result.getMillis();
}

From source file:com.todoroo.astrid.ui.ReminderControlSet.java

License:Open Source License

private void addNewAlarm() {
    pickNewAlarm(newDateTime().withMillisOfDay(0), new DateAndTimePickerDialog.OnDateTimePicked() {
        @Override/*w  ww  .  jav a2 s.c o m*/
        public void onDateTimePicked(DateTime dateTime) {
            addAlarmRow(dateTime.getMillis());
        }
    });
}

From source file:com.todoroo.astrid.ui.ReminderControlSet.java

License:Open Source License

private void addAlarmRow(final Long timestamp) {
    final View alertItem = addAlarmRow(getDisplayString(timestamp), timestamp, null);
    TextView display = (TextView) alertItem.findViewById(R.id.alarm_string);
    display.setOnClickListener(new OnClickListener() {
        @Override//from   ww w . j  a  va 2s .c o m
        public void onClick(View v) {
            pickNewAlarm(newDateTime(timestamp), new DateAndTimePickerDialog.OnDateTimePicked() {
                @Override
                public void onDateTimePicked(DateTime dateTime) {
                    long millis = dateTime.getMillis();
                    addAlarmRow(alertItem, getDisplayString(millis), millis, null);
                }
            });
        }
    });
}

From source file:com.tomtom.speedtools.thread.WorkQueue.java

License:Apache License

/**
 * Start workload, or wait if there is too much workload in the queue.
 *
 * @param workLoad Workload to be started.
 * @param timeout  Timeout in millis. If there is no room left in the queue before this timeout expires, the
 *                 workload is discarded and not scheduled. Use 0 for wait 'forever'.
 *///from   w  ww .  j  a v  a 2 s .  c  o m
@SuppressWarnings("CallToNotifyInsteadOfNotifyAll")
public void startOrWait(@Nonnull final Runnable workLoad, final long timeout) {
    assert timeout >= 0;
    assert !executor.isShutdown();
    assert Thread.currentThread().getId() == feederThread;

    final DateTime startTime = UTCTime.now();
    final long start = startTime.getMillis();
    DateTime nextDebugTime = startTime.plusSeconds(ISSUE_WAITING_LOG_LINE_AFTER_SECS);
    boolean scheduled = false;
    boolean again = false;
    int busyWait = BUSY_WAIT_MSECS_MIN;
    do {
        try {
            executor.execute(new RuntimeExceptionCatcher(workLoad));
            scheduled = true;
        } catch (final RejectedExecutionException ignored1) {
            assert !scheduled;
            try {
                //noinspection BusyWait
                Thread.sleep(busyWait);
                if (busyWait < BUSY_WAIT_MSECS_MAX) {
                    ++busyWait;
                }
                final DateTime now = UTCTime.now();
                final long timeWaiting = now.getMillis() - start;
                again = ((timeout == 0) || (timeWaiting < timeout));

                // Issue a log message only if timeout == 0 and task is rescheduled.
                if (again && (timeout == 0) && now.isAfter(nextDebugTime)) {
                    LOG.debug("startOrWait: workLoad not executed yet, already waiting {} secs...",
                            timeWaiting / 1000);
                    nextDebugTime = now.plusSeconds(ISSUE_WAITING_LOG_LINE_AFTER_SECS);
                }
            } catch (final InterruptedException ignored2) {
                assert !again;
            }
        }
    } while (!scheduled && again);
    if (!scheduled) {
        LOG.debug("startOrWait: workLoad was not scheduled, aborted after timeout={} msecs", timeout);
    }
}

From source file:com.tomtom.speedtools.thread.WorkQueue.java

License:Apache License

/**
 * Wait until the work pool finished executing all work load.
 *
 * @param timeout Max. wait time in msecs. Use 0 for 'forever'.
 * @return False if exceptions were caught during executing workload packages.
 *//*from  w w  w  .  j a  v a 2 s.  c om*/
public boolean waitUntilFinished(final long timeout) {
    assert timeout >= 0;
    assert !executor.isShutdown();
    assert Thread.currentThread().getId() == feederThread;

    LOG.debug("waitUntilFinished: shut down executor");
    executor.shutdown();

    final DateTime startTime = UTCTime.now();
    DateTime nextDebugTime = startTime.plusSeconds(ISSUE_WAITING_LOG_LINE_AFTER_SECS);
    boolean again = false;
    do {
        try {
            final DateTime now = UTCTime.now();
            if (now.isAfter(nextDebugTime)) {
                LOG.debug("waitUntilFinished: awaiting termination of executor for {} secs...",
                        (now.getMillis() - startTime.getMillis()) / 1000);
                nextDebugTime = now.plusSeconds(ISSUE_WAITING_LOG_LINE_AFTER_SECS);
            }
            again = !executor.awaitTermination((timeout == 0) ? ISSUE_WAITING_LOG_LINE_AFTER_SECS : timeout,
                    (timeout == 0) ? TimeUnit.SECONDS : TimeUnit.MILLISECONDS);
        } catch (final InterruptedException ignored) {
            // Ignored.
        }
    } while (again && (timeout == 0));
    LOG.debug("waitUntilFinished: executor terminated (creating new one)");

    /**
     *  Current pool is empty and done, get a new executor pool.
     *  Don't clear the exceptions list, as it is supposed to be the overall list for this
     *  WorkQueue instance (not fot the ThreadPoolExecutor instance).
     */
    executor = createNewExecutor();
    return exceptions.isEmpty();
}