Skip to content

Commit

Permalink
Fix #46 Make date comparison Locale independent
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Thomas <markt@apache.org>
  • Loading branch information
markt-asf committed Feb 12, 2019
1 parent 5400648 commit 5d63739
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Expand Up @@ -71,6 +71,8 @@

public class TestServlet extends HttpTCKServlet {

public static String CUSTOM_HEADER_DATE_FORMAT = "yyyy-MM-dd HH:mm";

public void cloneTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

Expand Down Expand Up @@ -542,7 +544,8 @@ public void setMaxAgeVer0PositiveTest(HttpServletRequest request,
testCookie.setVersion(0);

testCookie.setMaxAge(2);
SimpleDateFormat sdf = new SimpleDateFormat();
// Use a custom format to ensure Locale independence
SimpleDateFormat sdf = new SimpleDateFormat(CUSTOM_HEADER_DATE_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date currDate = new Date();
String dateString = sdf.format(currDate);
Expand Down
Expand Up @@ -352,7 +352,7 @@ public void setMaxAgePositiveTest() throws Fault {
}

// put expiry date into GMT
SimpleDateFormat sdf = new SimpleDateFormat();
SimpleDateFormat sdf = new SimpleDateFormat(TestServlet.CUSTOM_HEADER_DATE_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String resultStringDate = sdf.format(expiryDate);
try {
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.sun.ts.lib.util.TestUtil;
import com.sun.ts.tests.common.webclient.http.HttpRequest;
import com.sun.ts.tests.common.webclient.http.HttpResponse;
import com.sun.ts.tests.servlet.api.javax_servlet_http.cookie.TestServlet;
import com.sun.ts.tests.servlet.common.client.AbstractUrlClient;
import com.sun.ts.tests.servlet.common.util.Data;
import java.io.PrintWriter;
Expand Down Expand Up @@ -388,7 +389,7 @@ public void setMaxAgePositiveTest() throws Fault {
}

// put expiry date into GMT
SimpleDateFormat sdf = new SimpleDateFormat();
SimpleDateFormat sdf = new SimpleDateFormat(TestServlet.CUSTOM_HEADER_DATE_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String resultStringDate = sdf.format(expiryDate);
try {
Expand Down

0 comments on commit 5d63739

Please sign in to comment.