Skip to content

Commit

Permalink
fixes #525 (#530)
Browse files Browse the repository at this point in the history
* fixes #525

* Simply unit test.
  • Loading branch information
Linyu Chen authored and wumpz committed Oct 24, 2017
1 parent e23d4bc commit 1a1a1aa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/net/sf/jsqlparser/expression/TimestampValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@
public class TimestampValue implements Expression {

private Timestamp value;

private char quotation = '\'';
public TimestampValue(String value) {
this.value = Timestamp.valueOf(value.substring(1, value.length() - 1));
if (value == null) {
throw new java.lang.IllegalArgumentException("null string");
} else {
if (value.charAt(0) == quotation) {
this.value = Timestamp.valueOf(value.substring(1, value.length() - 1));
} else {
this.value = Timestamp.valueOf(value.substring(0, value.length()));
}
}
}

@Override
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/net/sf/jsqlparser/expression/TimestampValueTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.sf.jsqlparser.expression;

import net.sf.jsqlparser.JSQLParserException;
import org.junit.Test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
* @author Linyu Chen
*/
public class TimestampValueTest {

@Test
public void testTimestampValue_issue525() throws JSQLParserException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String currentDate = dateFormat.format(new Date());
TimestampValue tv = new TimestampValue(currentDate);
System.out.println(tv.toString());
}

@Test
public void testTimestampValueWithQuotation_issue525() throws JSQLParserException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String currentDate = dateFormat.format(new Date());
TimestampValue tv = new TimestampValue("'" + currentDate + "'");
System.out.println(tv.toString());
}
}

0 comments on commit 1a1a1aa

Please sign in to comment.