Last active
August 29, 2015 14:01
-
-
Save jfuerth/0924177f6501bc38552b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package ca.fuerth.misc; | |
| import static org.junit.Assert.*; | |
| import java.sql.Date; | |
| import java.text.DateFormat; | |
| import java.util.TimeZone; | |
| import org.junit.Test; | |
| public class SqlDateTest { | |
| @Test | |
| public void testCreatedWithMillis() { | |
| Date sqldate = new Date( 86400 * 1000 ); | |
| DateFormat df = DateFormat.getDateTimeInstance(); | |
| df.setTimeZone( TimeZone.getTimeZone( "GMT" ) ); | |
| System.out.println("Created with millis: " + df.format(sqldate)); | |
| assertEquals(86400 * 1000, sqldate.getTime()); | |
| assertEquals( 70, sqldate.getYear() ); | |
| assertEquals( 0, sqldate.getMonth() ); | |
| assertEquals( 2, sqldate.getDate() ); | |
| } | |
| @Test | |
| public void testCreatedWithYearMonthDay() { | |
| Date sqldate = new Date(70, 0, 2); | |
| DateFormat df = DateFormat.getDateTimeInstance(); | |
| df.setTimeZone( TimeZone.getTimeZone( "GMT" ) ); | |
| System.out.println("Created with YMD: " + df.format(sqldate)); | |
| assertEquals( 70, sqldate.getYear() ); | |
| assertEquals( 0, sqldate.getMonth() ); | |
| assertEquals( 2, sqldate.getDate() ); | |
| assertEquals("Timestamp wasn't exactly 24 hours from the epoch: " + sqldate.getTime() / (86400.0 * 1000) + " days", | |
| 86400 * 1000, sqldate.getTime()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment