// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.sps.data;

public final class TimeRange {
    
    private int start;
    private int duration;
    private int end;

    private TimeRange(int start, int duration) {
        this.start = start;
        this.duration = duration;
        this.end = start + duration;
    }

    /** Create new TimeRange with start time (in minutes) and end time (in minutes). */
    public static TimeRange fromStartToEnd(int start, int end) {
        return new TimeRange(start, end - start);
    }

    /** Create new TimeRange with start time (in minutes) and duration (in minutes). */
    public static TimeRange fromStartWithDuration(int start, int duration) {
        return new TimeRange(start, duration);
    }

    public int getStart() {
        return this.start;
    }

    public int getDuration() {
        return this.duration;
    }

    public int getEnd() {
        return this.end;
    }

    @Override
    public String toString() {
        return getMinutesInTime(start) + "-" + getMinutesInTime(end);
    }

    /** Converts hour:minutes time to minutes. */
    public static int getTimeInMinutes(int hours, int minutes) {
        if (hours < 0 || hours >= 24) {
            throw new IllegalArgumentException("Hours can only be 0 through 23 (inclusive).");
        }

        if (minutes < 0 || minutes >= 60) {
            throw new IllegalArgumentException("Minutes can only be 0 through 59 (inclusive).");
        }

        return (hours * 60) + minutes;
    }

    /** Converts minute times to hour:minutes time. */
    private String getMinutesInTime(int time) {
        String hour = String.valueOf(time / 60);
        String minutes = String.valueOf(time % 60);

        if(minutes.length() < 2) {
            minutes = "0" + minutes;
        }

        return hour + ":" + minutes;

    }

}

@@ -612,16 +612,44 @@
 .data;%0A%0A
+import java.util.Calendar;%0A%0A
 public f
@@ -745,16 +745,43 @@
 int end;
+%0A    private Calendar date;
 %0A%0A    pr
@@ -811,32 +811,47 @@
 rt, int duration
+, Calendar date
 ) %7B%0A        this
@@ -929,32 +929,58 @@
 art + duration;%0A
+        this.date = date;%0A
     %7D%0A%0A    /** C
@@ -1119,16 +1119,31 @@
  int end
+, Calendar date
 ) %7B%0A    
@@ -1185,16 +1185,22 @@
  - start
+, date
 );%0A    %7D
@@ -1362,16 +1362,31 @@
 duration
+, Calendar date
 ) %7B%0A    
@@ -1425,16 +1425,22 @@
 duration
+, date
 );%0A    %7D
@@ -1625,24 +1625,89 @@
 end;%0A    %7D%0A%0A
+    public Calendar getDate() %7B%0A        return this.date;%0A    %7D%0A%0A
     @Overrid

Add Calendar date to TimeRange.