/**
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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:
 *
 * http://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 org.jasig.portlet.calendar.mvc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import net.fortuna.ical4j.model.component.VEvent;

import org.joda.time.DateMidnight;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Interval;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;
import org.junit.Test;

/**
 * @author Jen Bourey, jbourey@unicon.net
 * @version $Revision$
 */
public class JsonCalendarEventTest {
	
	@Test
	public void testStartDate() {
		DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");

        DateTimeFormatter df = new DateTimeFormatterBuilder().appendDayOfWeekText()
                .appendLiteral(" ").appendMonthOfYearText().appendLiteral(" ")
                .appendDayOfMonth(1).toFormatter().withZone(tz);        
        
        DateTimeFormatter tf = new DateTimeFormatterBuilder().appendClockhourOfHalfday(1)
                .appendLiteral(":").appendMinuteOfHour(2).appendLiteral(" ")
                .appendHalfdayOfDayText().toFormatter().withZone(tz);

		DateTime date = new DateMidnight(2011, 1, 3, tz).toDateTime();
		
		DateTime start = new DateTime(2011, 1, 3, 4, 0, tz);
		DateTime end = start.plusDays(2);
		
		VEvent event = new VEvent(new net.fortuna.ical4j.model.DateTime(start.toDate()), new net.fortuna.ical4j.model.DateTime(end.toDate()), "Test Event");
		Interval eventInterval = new Interval(start, end);

		DateMidnight dateStart = new DateMidnight(date, tz);
		Interval day = new Interval(dateStart, dateStart.plusDays(1));
		CalendarDisplayEvent json = new CalendarDisplayEvent(event, eventInterval, day, df, tf);
		assertEquals("4:00 AM", json.getDateStartTime());
        assertEquals("12:00 AM", json.getDateEndTime());
		assertEquals("Monday January 3", json.getStartDate());
		assertEquals("Wednesday January 5", json.getEndDate());
		assertEquals("4:00 AM", json.getStartTime());
		assertEquals("4:00 AM", json.getEndTime());
		assertTrue(json.isMultiDay());
		assertFalse(json.isAllDay());
		
        day = new Interval(dateStart.plusDays(1), dateStart.plusDays(2));
		json = new CalendarDisplayEvent(event, eventInterval, day, df, tf);
		assertEquals("12:00 AM", json.getDateStartTime());
		assertEquals("12:00 AM", json.getDateEndTime());
        assertTrue(json.isMultiDay());
        assertTrue(json.isAllDay());
		
        day = new Interval(dateStart.plusDays(2), dateStart.plusDays(3));
		json = new CalendarDisplayEvent(event, eventInterval, day, df, tf);
		assertEquals("12:00 AM", json.getDateStartTime());
		assertEquals("4:00 AM", json.getDateEndTime());
        assertTrue(json.isMultiDay());
        assertFalse(json.isAllDay());
		
	}

}

@@ -938,16 +938,43 @@
 tFalse;%0A
+%0Aimport java.util.Locale;%0A%0A
 import n
@@ -1713,16 +1713,38 @@
 Zone(tz)
+.withLocale(Locale.US)
 ;       

fix DateTimeFormatter into test as it won't work on JVM with a different locale. Force it to use the US locale to test on lday label.