001/* 002 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit. 003 * 004 * Based in London, we are world leaders in the design and development 005 * of bespoke applications for the securities financing markets. 006 * 007 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> 008 * ___ _ _ _ _ _ 009 * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 010 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 011 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 012 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 013 * |__/ 014 * 015 * www.ObjectLab.co.uk 016 * 017 * $Id$ 018 * 019 * Copyright 2006 the original author or authors. 020 * 021 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 022 * use this file except in compliance with the License. You may obtain a copy of 023 * the License at 024 * 025 * http://www.apache.org/licenses/LICENSE-2.0 026 * 027 * Unless required by applicable law or agreed to in writing, software 028 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 029 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 030 * License for the specific language governing permissions and limitations under 031 * the License. 032 */ 033package net.objectlab.kit.datecalc.jdk8; 034 035import java.time.DayOfWeek; 036import java.time.LocalDate; 037 038import net.objectlab.kit.datecalc.common.WorkingWeek; 039 040/** 041 * Immutable class representing a WorkingWeek for the Joda implementation. 042 * 043 * @author Benoit Xhenseval 044 */ 045public class Jdk8WorkingWeek extends WorkingWeek { 046 047 private static final int MAX_WEEKDAY_INDEX = 7; 048 049 public static final Jdk8WorkingWeek DEFAULT = new Jdk8WorkingWeek(); 050 051 public Jdk8WorkingWeek() { 052 super(); 053 } 054 055 protected Jdk8WorkingWeek(final byte workingDays) { 056 super(workingDays); 057 } 058 059 public Jdk8WorkingWeek(final WorkingWeek ww) { 060 this(ww.getWorkingDays()); 061 } 062 063 // ----------------------------------------------------------------------- 064 // 065 // ObjectLab, world leaders in the design and development of bespoke 066 // applications for the securities financing markets. 067 // www.ObjectLab.co.uk 068 // 069 // ----------------------------------------------------------------------- 070 071 public boolean isWorkingDay(final LocalDate date) { 072 final int dayOfWeek = jdk8ToCalendarDayConstant(date.getDayOfWeek()); 073 return isWorkingDayFromCalendar(dayOfWeek); 074 } 075 076 /** 077 * Return a new JodaWorkingWeek if the status for the given day has changed. 078 * 079 * @param working 080 * true if working day 081 * @param givenDayOfWeek 082 * e.g. DateTimeConstants.MONDAY, DateTimeConstants.TUESDAY, etc 083 */ 084 public Jdk8WorkingWeek withWorkingDayFromDateTimeConstant(final boolean working, final DayOfWeek givenDayOfWeek) { 085 final int dayOfWeek = jdk8ToCalendarDayConstant(givenDayOfWeek); 086 return new Jdk8WorkingWeek(super.withWorkingDayFromCalendar(working, dayOfWeek)); 087 } 088 089 public boolean isWorkingDayFromDateTimeConstant(final DayOfWeek dayOfWeek) { 090 return isWorkingDayFromCalendar(jdk8ToCalendarDayConstant(dayOfWeek)); 091 } 092 093 public static int jdk8ToCalendarDayConstant(final DayOfWeek givenDayOfWeek) { 094 final int dayOfWeek = givenDayOfWeek.getValue() + 1; 095 return dayOfWeek <= MAX_WEEKDAY_INDEX ? dayOfWeek : dayOfWeek % MAX_WEEKDAY_INDEX; 096 } 097} 098 099/* 100 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit. 101 * 102 * Based in London, we are world leaders in the design and development 103 * of bespoke applications for the securities financing markets. 104 * 105 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a> 106 * ___ _ _ _ _ _ 107 * / _ \| |__ (_) ___ ___| |_| | __ _| |__ 108 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ 109 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | 110 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ 111 * |__/ 112 * 113 * www.ObjectLab.co.uk 114 */