Support positive offset in datetime

Fixes #31
This commit is contained in:
Moandji Ezana 2016-06-14 19:58:13 -04:00
parent a37dfd80a8
commit b7d3b34619
3 changed files with 14 additions and 2 deletions

View file

@ -9,6 +9,7 @@
## Fixed ## Fixed
* Transient fields are not written to TOML files (thanks to __[lare96](https://github.com/lare96)__) * Transient fields are not written to TOML files (thanks to __[lare96](https://github.com/lare96)__)
* Support positive timezone offset in datetime (thanks to __[aloyse](https://github.com/aloyse)__)
## 0.5.1 / 2016-01-24 ## 0.5.1 / 2016-01-24

View file

@ -40,7 +40,7 @@ class DateValueReaderWriter implements ValueReader, ValueWriter {
for (int i = index.get(); i < original.length(); i = index.incrementAndGet()) { for (int i = index.get(); i < original.length(); i = index.incrementAndGet()) {
char c = original.charAt(i); char c = original.charAt(i);
if (Character.isDigit(c) || c == '-' || c == ':' || c == '.' || c == 'T' || c == 'Z') { if (Character.isDigit(c) || c == '-' || c == '+' || c == ':' || c == '.' || c == 'T' || c == 'Z') {
sb.append(c); sb.append(c);
} else { } else {
index.decrementAndGet(); index.decrementAndGet();

View file

@ -27,7 +27,18 @@ public class DateTest {
Toml toml = new Toml().read("a_date = 1979-05-27T00:32:00-07:00"); Toml toml = new Toml().read("a_date = 1979-05-27T00:32:00-07:00");
Calendar calendar = Calendar.getInstance(UTC); Calendar calendar = Calendar.getInstance(UTC);
calendar.set(1979, Calendar.MAY, 27, 7, 32, 00); calendar.set(1979, Calendar.MAY, 27, 7, 32, 0);
calendar.set(Calendar.MILLISECOND, 0);
assertEquals(calendar.getTime(), toml.getDate("a_date"));
}
@Test
public void should_get_date_with_positive_offset() throws Exception {
Toml toml = new Toml().read("a_date = 1979-05-27T07:32:00+07:00");
Calendar calendar = Calendar.getInstance(UTC);
calendar.set(1979, Calendar.MAY, 27, 0, 32, 0);
calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.MILLISECOND, 0);
assertEquals(calendar.getTime(), toml.getDate("a_date")); assertEquals(calendar.getTime(), toml.getDate("a_date"));