jchronic
jchronic copied to clipboard
When using Past pointer option, JChronic parses date+time to the wrong date.
Here is an example. "2014-03-10 19:00" actually parses as 2014-03-09 19:00.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import org.junit.Test;
import com.mdimension.jchronic.Chronic;
import com.mdimension.jchronic.Options;
import com.mdimension.jchronic.tags.Pointer;
import com.mdimension.jchronic.utils.Span;
public class PenDownloadTest {
@Test public void testJchronicPast() {
TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
assertTrue(zone.observesDaylightTime());
Locale locale = Locale.US;
Calendar now = Calendar.getInstance(zone, locale);
now.clear();
now.set(2014, Calendar.MARCH, 13, 0, 0, 0);
Options options = new Options(Pointer.PointerType.PAST, now, false, 6);
Calendar expectedTime = Calendar.getInstance(zone, locale);
expectedTime.clear();
expectedTime.set(2014, Calendar.MARCH, 10, 19, 0);
Span expectedSpan = new Span(expectedTime, Calendar.SECOND, 1);
Span actualSpan = Chronic.parse("2014-03-10 19:00", options);
assertEquals(expectedSpan, actualSpan);
}
}
Thanks for pointing this out. A pull request would be awesome :) I can't say that I have time to track this down at the moment.