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.ofalvai.bpinfo.util.Utils.java

License:Apache License

/**
 * Returns whether an alert counts as a recent one based on the start timestamp.
 *///  w w  w.  j av a  2s.co m
public static boolean isAlertRecent(@NonNull Alert alert) {
    DateTime alertTime = new DateTime(alert.getStart() * 1000L);
    DateTime now = new DateTime();

    return alertTime.plusHours(Config.ALERT_RECENT_THRESHOLD_HOURS).getMillis() >= now.getMillis();
}

From source file:com.pacoapp.paco.model.ExperimentProviderUtil.java

License:Open Source License

@Override
public EventInterface getEvent(Long experimentServerId, DateTime scheduledTime, String groupName,
        Long actionTriggerId, Long scheduleId) {
    if (scheduledTime == null) {
        return null;
    }//from   w w w.  j  a  va2  s  .  co m
    String selectionClause = EventColumns.EXPERIMENT_SERVER_ID + " = ? " + " AND " + EventColumns.SCHEDULE_TIME
            + " = ? " + " AND " + EventColumns.GROUP_NAME + " = ? " + " AND " + EventColumns.ACTION_TRIGGER_ID
            + " = ? " + " AND " + EventColumns.ACTION_TRIGGER_SPEC_ID + " = ? ";

    String[] selectionArgs = new String[] { Long.toString(experimentServerId),
            Long.toString(scheduledTime.getMillis()), groupName, Long.toString(actionTriggerId),
            Long.toString(scheduleId) };

    Event event = findEventBy(selectionClause, selectionArgs, EventColumns._ID + " DESC");
    if (event != null) {
        Log.i(PacoConstants.TAG,
                "Found event for experimentId: " + experimentServerId + ", st = " + scheduledTime);
    } else {
        Log.i(PacoConstants.TAG,
                "DID NOT Find event for experimentId: " + experimentServerId + ", st = " + scheduledTime);
    }
    return event;
}

From source file:com.pacoapp.paco.triggering.AlarmCreator2.java

License:Open Source License

private void createAlarm(DateTime alarmTime, ExperimentDAO experiment) {
    Log.i(PacoConstants.TAG,//  w w w. ja  v a 2 s .c om
            "Creating alarm: " + alarmTime.toString() + " for experiment: " + experiment.getTitle());
    PendingIntent intent = createAlarmReceiverIntentForExperiment(alarmTime);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime.getMillis(), intent);
}

From source file:com.pacoapp.paco.triggering.NotificationCreator.java

License:Open Source License

private void createNewCustomNotificationForExperiment(Context context, DateTime time, ExperimentDAO experiment,
        String groupName, long expirationTimeInMillis, String message, Integer color, Boolean dismissible,
        Long actionTriggerSpecId, Long actionTriggerId, Long actionId) {
    NotificationHolder notificationHolder = new NotificationHolder(time.getMillis(), experiment.getId(), 0,
            expirationTimeInMillis, groupName, actionTriggerId, actionId,
            NotificationHolder.CUSTOM_GENERATED_NOTIFICATION, message, actionTriggerSpecId);

    experimentProviderUtil.insertNotification(notificationHolder);
    fireNotification(context, notificationHolder, experiment.getTitle(), message, experiment.getRingtoneUri(),
            color, dismissible);/*from   w w  w  .  jav  a  2  s . co  m*/
    createAlarmToCancelNotificationAtTimeout(context, notificationHolder);
}

From source file:com.pacoapp.paco.triggering.NotificationCreator.java

License:Open Source License

private void createAlarmForSnooze(Context context, NotificationHolder notificationHolder) {
    DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime());
    Experiment experiment = experimentProviderUtil
            .getExperimentByServerId(notificationHolder.getExperimentId());
    Integer snoozeTime = notificationHolder.getSnoozeTime();
    if (snoozeTime == null) {
        snoozeTime = DEFAULT_SNOOZE_10_MINUTES;
    }//from  w w w.  j  a  va  2 s.  c o  m
    int snoozeMinutes = snoozeTime / MILLIS_IN_MINUTE;
    DateTime timeoutMinutes = new DateTime(alarmTime).plusMinutes(snoozeMinutes);
    long snoozeDurationInMillis = timeoutMinutes.getMillis();

    Log.i(PacoConstants.TAG,
            "Creating snooze alarm to resound notification for holder: " + notificationHolder.getId()
                    + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = "
                    + new DateTime(alarmTime).toString() + " waking up from snooze in " + timeoutMinutes
                    + " minutes");

    Intent ultimateIntent = new Intent(context, AlarmReceiver.class);
    Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI,
            notificationHolder.getId().toString());
    ultimateIntent.setData(uri);
    ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue());
    ultimateIntent.putExtra(SNOOZE_REPEATER_EXTRA_KEY, true);

    PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 3, ultimateIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, snoozeDurationInMillis, intent);
}

From source file:com.pacoapp.paco.ui.ExperimentExecutorCustomRendering.java

License:Open Source License

private WebViewClient createWebViewClientThatHandlesFileLinksForCharts() {
    WebViewClient webViewClient = new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);/*  w  w w.  j a  v  a2  s .  c om*/
            if (uri.getScheme().startsWith("http")) {
                return true; // throw away http requests - we don't want 3rd party javascript sending url requests due to security issues.
            }

            String inputName = uri.getQueryParameter("inputName");
            if (inputName == null) {
                return true;
            }
            JSONArray results = new JSONArray();
            for (Event event : experiment.getEvents()) {
                JSONArray eventJson = new JSONArray();
                DateTime responseTime = event.getResponseTime();
                if (responseTime == null) {
                    continue; // missed signal;
                }
                eventJson.put(responseTime.getMillis());
                // in this case we are looking for one input from the responses that we are charting.
                for (Output response : event.getResponses()) {
                    if (response.getAnswer().equals(inputName)) {
                        Input2 input = ExperimentHelper.getInputWithName(experiment.getExperimentDAO(),
                                inputName, null);
                        if (input.isNumeric()) {
                            eventJson.put(response.getDisplayOfAnswer(input));
                            results.put(eventJson);
                            continue;
                        }
                    }
                }

            }
            env.put("data", results.toString());
            env.put("inputName", inputName);

            view.loadUrl(stripQuery(url));
            return true;
        }

    };
    return webViewClient;
}

From source file:com.pacoapp.paco.ui.FeedbackActivity.java

License:Open Source License

private WebViewClient createWebViewClientThatHandlesFileLinksForCharts(
        final com.pacoapp.paco.shared.model2.Feedback feedback) {
    WebViewClient webViewClient = new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);/*from   w w w.  jav a2s. c o  m*/
            if (uri.getScheme().startsWith("http")) {
                return true; // throw away http requests - we don't want 3rd party javascript sending url requests due to security issues.
            }

            String inputIdStr = uri.getQueryParameter("inputId");
            if (inputIdStr == null) {
                return true;
            }

            JSONArray results = new JSONArray();
            experimentProviderUtil.loadEventsForExperiment(experiment);
            for (Event event : experiment.getEvents()) {
                JSONArray eventJson = new JSONArray();
                DateTime responseTime = event.getResponseTime();
                if (responseTime == null) {
                    continue; // missed signal;
                }
                eventJson.put(responseTime.getMillis());

                // in this case we are looking for one input from the responses that we are charting.
                for (Output response : event.getResponses()) {
                    if (response.getName().equals(inputIdStr)) {
                        Input2 inputById = ExperimentHelper.getInputWithName(experiment.getExperimentDAO(),
                                inputIdStr, null);
                        if (inputById.isNumeric()) {
                            eventJson.put(response.getDisplayOfAnswer(inputById));
                            results.put(eventJson);
                            continue;
                        }
                    }
                }

            }
            env.put("data", results.toString());
            env.put("inputId", inputIdStr);

            view.loadUrl(stripQuery(url));
            return true;
        }

    };
    return webViewClient;
}

From source file:com.passwordboss.android.analytics.AnalyticsHelperSegment.java

public static boolean checkTime(Context mContext, String item) {
    String storedDate = "";
    boolean sendData = false;
    if (Pref.SEGMENT_FLUSH.equals(item)) {
        storedDate = Pref.getValue(mContext, Pref.SEGMENT_FLUSH, "");
    } else if (Constants.ACTIVE_USER_ANALYTIC.equals(item)) {
        storedDate = Pref.getValue(mContext, Constants.ACTIVE_USER_ANALYTIC, "");
    }/*from  w w w.j ava  2s.  c  o m*/

    if (storedDate.length() > 0) {
        DateTime d1 = DateTime.now();
        DateTime d2 = DateTime.parse(storedDate, DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss"));
        long diff = d1.getMillis() - d2.getMillis();
        if (diff > diff) { // // TODO: 3/4/2016 figure out what would be implemented there
            sendData = true;
        }
    } else {
        sendData = true;
    }
    return sendData;
}

From source file:com.peertopark.java.dates.Dates.java

License:Apache License

public static Date from(DateTime dateTime) {
    if (Objects.isNull(dateTime)) {
        return null;
    } else {//from   ww  w  .ja va  2 s.  co m
        return new Date(dateTime.getMillis());
    }
}

From source file:com.pinterest.deployservice.scm.GithubManager.java

License:Apache License

private long getDate(Map<String, Object> jsonMap) {
    Map<String, Object> commiterMap = (Map<String, Object>) jsonMap.get("committer");
    String dateGMTStr = (String) commiterMap.get("date");
    DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis();
    DateTime dt = parser.parseDateTime(dateGMTStr);
    return dt.getMillis();
}