Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using Past pointer option, JChronic parses date+time to the wrong date. #6

Open
yonran opened this issue Mar 12, 2014 · 1 comment

Comments

@yonran
Copy link

yonran commented Mar 12, 2014

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);
    }

}
@samtingleff
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants