samtingleff / jchronic Goto Github PK
View Code? Open in Web Editor NEWNatural language date parsing in Java, ported directly from Ruby's chronic
License: MIT License
Natural language date parsing in Java, ported directly from Ruby's chronic
License: MIT License
When parsing "last sunday", with the default timezone set to UTC+1 and options.now set to UTC, the resulting date is Sun 10AM UTC+1, not Sun 12AM UTC as I would expect (since now is UTC). The issue stems from Time.java, which doesn't copy the timezone:
public static Calendar y(Calendar basis) {
Calendar clone = Calendar.getInstance();
clone.clear();
clone.set(Calendar.YEAR, basis.get(Calendar.YEAR));
return clone;
}
Hello team,
I appreciate the fantastic work done by you all in building this library. I have used this in my project and it works great!
However, there's been a vulnerability discovered during 2020 that pertains to JUnit4. Can we please update JUnit to the latest version (https://mvnrepository.com/artifact/junit/junit/4.13.2)?
Thanks in advance,
Cheers!
ISO 8601 format (yyyy-MM-dd'T'HH:mm:ss'Z') is not being parsed at all.
Running: mvn test
On: 0.2.7-SNAPSHOT
Failed tests: test_parse_guess_o_r_g_r(com.mdimension.jchronic.ParserTest): expected:Fri Mar 16 12:30:00 GMT 2007 but was:Fri Mar 16 11:30:00 GMT 2007
-------------------------------------------------------------------------------
Test set: com.mdimension.jchronic.ParserTest
-------------------------------------------------------------------------------
Tests run: 18, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.118 sec
test_parse_guess_o_r_g_r(com.mdimension.jchronic.ParserTest) Time elapsed: 0.006 sec
junit.framework.AssertionFailedError: expected:Fri Mar 16 12:30:00 GMT 2007 but was:Fri Mar 16 11:30:00 GMT 2007
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.failNotEquals(Assert.java:283)
at junit.framework.Assert.assertEquals(Assert.java:64)
at junit.framework.Assert.assertEquals(Assert.java:71)
at com.mdimension.jchronic.ParserTest.assertEquals(ParserTest.java:26)
at com.mdimension.jchronic.ParserTest.assertEquals(ParserTest.java:22)
at com.mdimension.jchronic.ParserTest.test_parse_guess_o_r_g_r(ParserTest.java:598)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Chronic.parse("2 days from now") returns null when running under Android. On the other hand Chronic.parse("tomorrow") works fine.
works fine when running under the JVM
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);
}
}
Using the code
Span d = Chronic.parse(date);
With date referring to the examples below.
This doesn't parse (the variable d above returns null):
2012-11-18 12:44:11 -0500
It seems the negative timezone is making the library fail.
When you remove "-0500" it does parse.
Can we please support negative timezones?
Hi - I just picked up this class and it looks quite good, but I would really like some end user documentation on the allowed formats and how they correspond to ranges. For now, the best I can find is:
https://github.com/samtingleff/jchronic/blob/master/src/test/java/com/mdimension/jchronic/ParserTest.java
http://chronic.rubyforge.org
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.