001package biweekly.property;
002
003import java.util.List;
004
005import biweekly.ICalVersion;
006import biweekly.Warning;
007import biweekly.component.ICalComponent;
008import biweekly.util.ICalDate;
009import biweekly.util.UtcOffset;
010
011/*
012 Copyright (c) 2013-2015, Michael Angstadt
013 All rights reserved.
014
015 Redistribution and use in source and binary forms, with or without
016 modification, are permitted provided that the following conditions are met: 
017
018 1. Redistributions of source code must retain the above copyright notice, this
019 list of conditions and the following disclaimer. 
020 2. Redistributions in binary form must reproduce the above copyright notice,
021 this list of conditions and the following disclaimer in the documentation
022 and/or other materials provided with the distribution. 
023
024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
025 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
028 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034 */
035
036/**
037 * Represents daylight savings time information.
038 * @author Michael Angstadt
039 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.23</a>
040 */
041public class Daylight extends ICalProperty {
042        private boolean daylight;
043        private UtcOffset offset;
044        private ICalDate start, end;
045        private String standardName, daylightName;
046
047        /**
048         * Creates a daylight savings property which states that the timezone does
049         * not observe daylight savings time.
050         */
051        public Daylight() {
052                this.daylight = false;
053        }
054
055        /**
056         * Creates a daylight savings property.
057         * @param daylight true if the timezone observes daylight savings time,
058         * false if not
059         * @param offset the UTC offset of daylight savings time
060         * @param start the start date of daylight savings time
061         * @param end the end date of daylight savings time
062         * @param standardName the timezone's name for standard time (e.g. "EST")
063         * @param daylightName the timezone's name for daylight savings time (e.g.
064         * "EDT")
065         */
066        public Daylight(boolean daylight, UtcOffset offset, ICalDate start, ICalDate end, String standardName, String daylightName) {
067                this.daylight = daylight;
068                this.offset = offset;
069                this.start = start;
070                this.end = end;
071                this.standardName = standardName;
072                this.daylightName = daylightName;
073        }
074
075        /**
076         * Gets whether this timezone observes daylight savings time.
077         * @return true if it observes daylight savings time, false if not
078         */
079        public boolean isDaylight() {
080                return daylight;
081        }
082
083        /**
084         * Sets whether this timezone observes daylight savings time.
085         * @param daylight true if it observes daylight savings time, false if not
086         */
087        public void setDaylight(boolean daylight) {
088                this.daylight = daylight;
089        }
090
091        /**
092         * Gets the UTC offset of daylight savings time.
093         * @return the UTC offset
094         */
095        public UtcOffset getOffset() {
096                return offset;
097        }
098
099        /**
100         * Sets the UTC offset of daylight savings time.
101         * @param offset the UTC offset
102         */
103        public void setOffset(UtcOffset offset) {
104                this.offset = offset;
105        }
106
107        /**
108         * Gets the start date of dayight savings time.
109         * @return the start date
110         */
111        public ICalDate getStart() {
112                return start;
113        }
114
115        /**
116         * Sets the start date of dayight savings time.
117         * @param start the start date
118         */
119        public void setStart(ICalDate start) {
120                this.start = start;
121        }
122
123        /**
124         * Gets the end date of daylight savings time.
125         * @return the end date
126         */
127        public ICalDate getEnd() {
128                return end;
129        }
130
131        /**
132         * Sets the end date of daylight savings time.
133         * @param end the end date
134         */
135        public void setEnd(ICalDate end) {
136                this.end = end;
137        }
138
139        /**
140         * Gets the name for standard time.
141         * @return the name (e.g. "EST")
142         */
143        public String getStandardName() {
144                return standardName;
145        }
146
147        /**
148         * Sets the name for standard time.
149         * @param name the name (e.g. "EST")
150         */
151        public void setStandardName(String name) {
152                this.standardName = name;
153        }
154
155        /**
156         * Gets the name of daylight savings time.
157         * @return the name (e.g. "EDT")
158         */
159        public String getDaylightName() {
160                return daylightName;
161        }
162
163        /**
164         * Sets the name of daylight savings time.
165         * @param name the name (e.g. "EDT")
166         */
167        public void setDaylightName(String name) {
168                this.daylightName = name;
169        }
170
171        @Override
172        protected void validate(List<ICalComponent> components, ICalVersion version, List<Warning> warnings) {
173                if (daylight && (offset == null || start == null || end == null || standardName == null || daylightName == null)) {
174                        warnings.add(Warning.validate(43));
175                }
176        }
177}