Java ZonedDateTime Calculate getStartOfWeek(ZoneId zoneId, ZonedDateTime time)

Here you can find the source of getStartOfWeek(ZoneId zoneId, ZonedDateTime time)

Description

get Start Of Week

License

Mozilla Public License

Declaration

public static ZonedDateTime getStartOfWeek(ZoneId zoneId, ZonedDateTime time) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2017 Stichting Yona Foundation This Source Code Form is subject to the terms of the Mozilla Public License, v.
 * 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *******************************************************************************/

import java.time.DayOfWeek;
import java.time.LocalDate;

import java.time.ZoneId;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

public class Main {
    public static ZonedDateTime getStartOfWeek(ZoneId zoneId, ZonedDateTime time) {
        LocalDate date = getStartOfDay(zoneId, time).toLocalDate();
        return getStartOfWeek(date).atStartOfDay(zoneId);
    }/*from   www  .j a va 2  s  . com*/

    public static LocalDate getStartOfWeek(LocalDate date) {
        if (date.getDayOfWeek() == DayOfWeek.SUNDAY) {
            // take as the first day of week
            return date;
        }

        return date.minusDays(date.getDayOfWeek().getValue());
    }

    public static ZonedDateTime getStartOfDay(ZoneId zoneId, ZonedDateTime time) {
        return time.withZoneSameInstant(zoneId).truncatedTo(ChronoUnit.DAYS);
    }
}

Related

  1. filter(final Set list, final ZonedDateTime base, final long minute)
  2. findIdx(int startidx, int endidx, ZonedDateTime endDate, List holidays)
  3. getDuration(ZonedDateTime input, TemporalField roundTo, int roundIncrement)
  4. getShortStringDate(ZonedDateTime time)
  5. getStartOfDay(ZoneId zoneId, ZonedDateTime time)
  6. getTime(ZonedDateTime zonedTime)
  7. getTimePath(Path dir, String ext, ZonedDateTime dateTime)
  8. getZonedDateTimeForComparison(TimeZone zone)
  9. holidaysInRange(ZonedDateTime startDate, ZonedDateTime endDate, List holidays)