Search in sources :

Example 1 with LocalDateTime

use of org.threeten.bp.LocalDateTime in project wire-android by wireapp.

the class DevicesPreferencesUtil method getActivationSummary.

private static String getActivationSummary(Context context, OtrClient otrClient) {
    LocalDateTime now = LocalDateTime.now(ZoneId.systemDefault());
    String time = ZTimeFormatter.getSeparatorTime(context, now, LocalDateTime.ofInstant(otrClient.getRegTime(), ZoneId.systemDefault()), DateFormat.is24HourFormat(context), ZoneId.systemDefault(), false);
    Location location = otrClient.getRegLocation();
    String regLocation = location == null ? "" : location.getDisplayName();
    return context.getString(R.string.pref_devices_device_activation_summary, time, StringUtils.isBlank(regLocation) ? UNKNOWN_LOCATION : regLocation);
}
Also used : LocalDateTime(org.threeten.bp.LocalDateTime) Location(com.waz.api.Location)

Example 2 with LocalDateTime

use of org.threeten.bp.LocalDateTime in project spring-data-commons by spring-projects.

the class ThreeTenBackPortConvertersUnitTests method convertsLocalDateTimeToDate.

// DATACMNS-606
@Test
public void convertsLocalDateTimeToDate() {
    LocalDateTime now = LocalDateTime.now();
    assertThat(format(CONVERSION_SERVICE.convert(now, Date.class), "yyyy-MM-dd'T'HH:mm:ss.SSS")).isEqualTo(now.toString());
}
Also used : LocalDateTime(org.threeten.bp.LocalDateTime) Date(java.util.Date) LocalDate(org.threeten.bp.LocalDate) Test(org.junit.Test)

Example 3 with LocalDateTime

use of org.threeten.bp.LocalDateTime in project SeriesGuide by UweTrottmann.

the class TimeTools method getShowReleaseDateTime.

@VisibleForTesting
@NonNull
public static ZonedDateTime getShowReleaseDateTime(@NonNull LocalTime time, int weekDay, @NonNull ZoneId timeZone, @Nullable String country, @Nullable String network, @NonNull Clock clock) {
    // create current date in show time zone, set local show release time
    LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(clock), time);
    // for daily shows (weekDay == 0) just use the current day
    if (weekDay >= 1 && weekDay <= 7) {
        // so if we want a week day earlier in the week, advance by 7 days first
        if (weekDay < localDateTime.getDayOfWeek().getValue()) {
            localDateTime = localDateTime.plusWeeks(1);
        }
        localDateTime = localDateTime.with(ChronoField.DAY_OF_WEEK, weekDay);
    }
    localDateTime = handleHourPastMidnight(country, network, localDateTime);
    // get a valid datetime in the show time zone, this auto-forwards time if inside DST gap
    ZonedDateTime dateTime = localDateTime.atZone(timeZone);
    // handle time zone effects on release time for US shows (only if device is set to US zone)
    String localTimeZone = TimeZone.getDefault().getID();
    if (localTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) {
        dateTime = applyUnitedStatesCorrections(country, localTimeZone, dateTime);
    }
    return dateTime;
}
Also used : LocalDateTime(org.threeten.bp.LocalDateTime) ZonedDateTime(org.threeten.bp.ZonedDateTime) VisibleForTesting(androidx.annotation.VisibleForTesting) NonNull(androidx.annotation.NonNull)

Example 4 with LocalDateTime

use of org.threeten.bp.LocalDateTime in project Eye by tommyolsson.

the class MainActivity method buildEvent.

/* Takes a JSONObject and constructs a EventClass object  */
private EventClass buildEvent(JSONObject object) throws JSONException {
    // get event information
    String id = object.getString("id");
    String subject = object.getString("subject");
    String bodyPreview = object.getString("bodyPreview");
    String importance = object.getString("importance");
    // whole day activity
    Boolean isAllDay = Boolean.parseBoolean(object.getString("isAllDay"));
    // Check if event is a meeting (if event marked private it is a meeting)
    Boolean isMeeting = false;
    int numOfAcceptedAttendees = 0;
    Boolean isAttending = false;
    if (object.getString("sensitivity").equals("private")) {
        isMeeting = true;
        JSONArray attendees = object.getJSONArray("attendees");
        for (int i = 0; i < attendees.length(); i++) {
            String userId = authResult.getUser().getDisplayableId();
            if (attendees.getJSONObject(i).getJSONObject("emailAddress").getString("address").equals(userId)) {
                if (attendees.getJSONObject(i).getJSONObject("status").getString("response").equals("accepted"))
                    isAttending = true;
                else if (attendees.getJSONObject(i).getJSONObject("status").getString("response").equals("tentativelyAccepted"))
                    isAttending = true;
            }
            if (attendees.getJSONObject(i).getJSONObject("status").getString("response").equals("tentativelyAccepted"))
                numOfAcceptedAttendees++;
        }
    }
    // Get string and create local date time objects (start and end date+time)
    LocalDateTime startTimeObj = getDateTimeFromString(object.getString("start"));
    LocalDateTime endTimeObj = getDateTimeFromString(object.getString("end"));
    // Get event location
    EventClass.Location location;
    try {
        location = getLocationFromJson(object.getJSONObject("location"));
    } catch (JSONException e) {
        location = new EventClass.Location();
    }
    // Get event ResponseStatus
    EventClass.ResponseStatus responseStatus;
    try {
        responseStatus = getResponseStatusFromJson(object.getJSONObject("responseStatus"));
    } catch (JSONException e) {
        responseStatus = new EventClass.ResponseStatus();
    }
    return new EventClass(id, subject, bodyPreview, isAllDay, isMeeting, isAttending, startTimeObj, endTimeObj, location, responseStatus, numOfAcceptedAttendees, importance);
}
Also used : LocalDateTime(org.threeten.bp.LocalDateTime) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 5 with LocalDateTime

use of org.threeten.bp.LocalDateTime in project Eye by tommyolsson.

the class MainActivity method getDateTimeFromString.

/* Converts a String to a LocalDateTime Object */
private LocalDateTime getDateTimeFromString(String string) {
    // Get startDate and startTime from JsonString
    String[] segments = string.split("\"");
    LocalDateTime ldt = LocalDateTime.parse(segments[3].substring(0, 16));
    // Add one extra hour to correct for daylight savings (!!)
    ldt.plusHours(1);
    return ldt;
}
Also used : LocalDateTime(org.threeten.bp.LocalDateTime)

Aggregations

LocalDateTime (org.threeten.bp.LocalDateTime)6 LocalDate (org.threeten.bp.LocalDate)2 ZonedDateTime (org.threeten.bp.ZonedDateTime)2 NonNull (androidx.annotation.NonNull)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 Location (com.waz.api.Location)1 Date (java.util.Date)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 Test (org.junit.Test)1 Instant (org.threeten.bp.Instant)1