Example usage for org.joda.time Period toStandardWeeks

List of usage examples for org.joda.time Period toStandardWeeks

Introduction

In this page you can find the example usage for org.joda.time Period toStandardWeeks.

Prototype

public Weeks toStandardWeeks() 

Source Link

Document

Converts this period to a period in weeks assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

Usage

From source file:de.azapps.mirakel.sync.taskwarrior.model.TaskWarriorTaskSerializer.java

License:Open Source License

public static void handleRecurrence(final JsonObject json, final Recurring r) {
    if (r == null) {
        Log.wtf(TAG, "recurring is null");
        return;//from  w  w w .j  a  va  2s  .  co m
    }
    if (!r.getWeekdays().isEmpty()) {
        switch (r.getWeekdays().size()) {
        case 1:
            json.addProperty("recur", "weekly");
            return;
        case 7:
            json.addProperty("recur", "daily");
            return;
        case 5:
            final List<Integer> weekdays = r.getWeekdays();
            for (Integer i = DateTimeConstants.MONDAY; i <= DateTimeConstants.FRIDAY; i++) {
                if (!weekdays.contains(i)) {
                    Log.w(TAG, "unsupported recurrence");
                    return;
                }
            }
            json.addProperty("recur", "weekdays");
            return;
        default:
            Log.w(TAG, "unsupported recurrence");
            return;
        }
    }
    final long interval = r.getIntervalMs() / (1000L * 60L);
    if (interval > 0L) {
        Period p = r.getInterval();
        if (r.getInterval().getMinutes() > 0) {
            json.addProperty("recur", p.toStandardMinutes().getMinutes() + "mins");
        } else if (r.getInterval().getHours() > 0) {
            json.addProperty("recur", p.toStandardHours().getHours() + "hours");
        } else if (r.getInterval().getDays() > 0) {
            json.addProperty("recur", p.toStandardDays().getDays() + "days");
        } else if (r.getInterval().getWeeks() > 0) {
            json.addProperty("recur", p.toStandardWeeks().getWeeks() + "weeks");
        } else if (r.getInterval().getMonths() > 0) {
            json.addProperty("recur", p.getMonths() + (12 * p.getYears()) + "months");
        } else {
            json.addProperty("recur", p.getYears() + "years");
        }
    }
}