Example usage for org.joda.time LocalDate minusDays

List of usage examples for org.joda.time LocalDate minusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate minusDays.

Prototype

public LocalDate minusDays(int days) 

Source Link

Document

Returns a copy of this date minus the specified number of days.

Usage

From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java

License:Apache License

/**
 * Parses the provided configuration and creates holidays for the provided
 * year.//from www.ja v a2 s.co  m
 */
public void parse(int year, Set<Holiday> holidays, final Holidays config) {
    for (FixedWeekdayRelativeToFixed f : config.getFixedWeekdayRelativeToFixed()) {
        if (!isValid(f, year)) {
            continue;
        }
        LocalDate day = calendarUtil.create(year, f.getDay());
        day = moveDateToFirstOccurenceOfWeekday(f, day);
        int days = determineNumberOfDays(f);
        day = f.getWhen() == When.AFTER ? day.plusDays(days) : day.minusDays(days);
        HolidayType type = xmlUtil.getType(f.getLocalizedType());
        holidays.add(new Holiday(day, f.getDescriptionPropertiesKey(), type));
    }
}

From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java

License:Apache License

/**
 * Moves the day to the first/next occurrence of the weekday and direction specified
 * @param f the specification of the weekday and direction of movement
 * @param day the day to move//from   w w  w.j  av a  2  s  . co m
 * @return the day moved to the weekday and in the direction as specified
 */
private LocalDate moveDateToFirstOccurenceOfWeekday(FixedWeekdayRelativeToFixed f, LocalDate day) {
    LocalDate movingDay = day;
    do {
        movingDay = f.getWhen() == When.AFTER ? movingDay.plusDays(1) : movingDay.minusDays(1);
    } while (movingDay.getDayOfWeek() != xmlUtil.getWeekday(f.getWeekday()));
    return movingDay;
}

From source file:com.leonarduk.finance.utils.DateUtils.java

License:Open Source License

public static LocalDate getPreviousDate(final LocalDate currentDate) {
    final LocalDate returnDate = currentDate.minusDays(1);
    if ((returnDate.getDayOfWeek() == DateTimeConstants.SATURDAY)
            || (returnDate.getDayOfWeek() == DateTimeConstants.SUNDAY)) {
        return DateUtils.getPreviousDate(returnDate);
    }/* w w  w .  j  a  v  a  2  s  .c  om*/
    return returnDate;
}

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

@NonNull
private LocalDateTime getTimeCal(@Nullable LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();/* w w w.  j ava  2s.  c  o m*/
    }
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time <= -1) {
            date = date.minusDays(1);
            time += 6;
        }
    }

    LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time)));
    int h = timeCal.getHourOfDay();
    if ((time >= 3) && (h < 5)) {
        timeCal = timeCal.plusDays(1);
    }
    return timeCal;
}

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

public String getTime(@Nullable LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();/* www  . ja v a 2s . co  m*/
    }
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time == -1) {
            date = date.minusDays(1);
            time += 6;
        }

    }
    return adj(_getTime(date, time), time);
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

@NonNull
public LocalDate getFirstSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;/*ww  w.ja v a 2s  . c o  m*/
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String times[] = { this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2),
                this.times.get(prefix + 3), this.times.get(prefix + 4), this.times.get(prefix + 5) };
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.plusDays(1);
        }
        i++;
        date = date.minusDays(1);
    }
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

@NonNull
public LocalDate getLastSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;/*from w w  w. j  av a  2s.  c o  m*/
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String times[] = { this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2),
                this.times.get(prefix + 3), this.times.get(prefix + 4), this.times.get(prefix + 5) };
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.minusDays(1);
        }
        i++;
        date = date.plusDays(1);
    }
}

From source file:com.prayer.vakit.times.Times.java

License:Apache License

public LocalDateTime getTimeCal(LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();//from  w  w  w.  ja  v a2  s. co  m
    }
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time <= -1) {
            date = date.minusDays(1);
            time += 6;
        }
    }

    LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time)));
    int h = timeCal.getHourOfDay();
    if ((time >= 3) && (h < 5)) {
        timeCal = timeCal.plusDays(1);
    }
    return timeCal;
}

From source file:com.prayer.vakit.times.Times.java

License:Apache License

public String getTime(LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();//  w w w .j  a  va2 s  .  c  o m
    }
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time == -1) {
            date = date.minusDays(1);
            time += 6;
        }

    }
    String ret = adj(_getTime(date, time), time);
    return ret;
}

From source file:com.redhat.engineering.jenkins.report.plugin.ReportPluginPortlet.java

License:Open Source License

/**
 * Graph of duration of tests over time.
 *//* w  w  w .  j  av  a  2s.c o  m*/
public Graph getSummaryGraph() {
    // The standard equals doesn't work because two LocalDate objects can
    // be differente even if the date is the same (different internal timestamp)
    Comparator<LocalDate> localDateComparator = new Comparator<LocalDate>() {

        @Override
        public int compare(LocalDate d1, LocalDate d2) {
            if (d1.isEqual(d2)) {
                return 0;
            }
            if (d1.isAfter(d2)) {
                return 1;
            }
            return -1;
        }
    };

    // We need a custom comparator for LocalDate objects
    final Map<LocalDate, TestResultAggrSummary> summaries = //new HashMap<LocalDate, TestResultSummary>();
            new TreeMap<LocalDate, TestResultAggrSummary>(localDateComparator);
    LocalDate today = new LocalDate();

    // for each job, for each day, add last build of the day to summary
    for (Job job : getDashboard().getJobs()) {
        Filter filter = job.getAction(ReportPluginProjectAction.class).getInitializedFilter();
        filter.addCombinationFilter(combinationFilter);
        Run run = job.getFirstBuild();

        if (run != null) { // execute only if job has builds
            LocalDate runDay = new LocalDate(run.getTimestamp());
            LocalDate firstDay = (dateRange != 0) ? new LocalDate().minusDays(dateRange) : runDay;

            while (run != null) {
                runDay = new LocalDate(run.getTimestamp());
                Run nextRun = run.getNextBuild();

                if (nextRun != null) {
                    LocalDate nextRunDay = new LocalDate(nextRun.getTimestamp());
                    // skip run before firstDay, but keep if next build is after start date
                    if (!runDay.isBefore(firstDay)
                            || runDay.isBefore(firstDay) && !nextRunDay.isBefore(firstDay)) {
                        // if next run is not the same day, use this test to summarize
                        if (nextRunDay.isAfter(runDay)) {
                            summarize(summaries, run.getAction(ReportPluginBuildAction.class).getTestResults(),
                                    filter, (runDay.isBefore(firstDay) ? firstDay : runDay),
                                    nextRunDay.minusDays(1));
                        }
                    }
                } else {
                    // use this run's test result from last run to today
                    summarize(summaries, run.getAction(ReportPluginBuildAction.class).getTestResults(), filter,
                            (runDay.isBefore(firstDay) ? firstDay : runDay), today);
                }
                run = nextRun;
            }
        }
    }

    return new Graph(-1, getGraphWidth(), getGraphHeight()) {

        protected JFreeChart createGraph() {
            return GraphHelper.createChart(buildDataSet(summaries));
        }
    };
}