public void testSetDefault() { Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMMSS); assertEquals("12:34:56", Time.writeTime(12*3600 + 34*60 + 56.789)); Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMM); assertEquals("12:34", Time.writeTime(12*3600 + 34*60 + 56.789)); Time.setDefaultTimeFormat(Time.TIMEFORMAT_SSSS); assertEquals(Integer.toString(12*3600 + 34*60 + 56), Time.writeTime(12*3600 + 34*60 + 56.789)); Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMMSSDOTSS); assertEquals("12:34:56.78", Time.writeTime(12*3600 + 34*60 + 56.789).substring(0, 11)); // (conversion to double of .789 looks like .788999999999... thus that dirty trick. // kai/gregor, nov'11) }
public void testWriting() { Time.setDefaultTimeFormat(Time.TIMEFORMAT_HHMMSS); assertEquals( "12:34:56", Time.writeTime( 12*3600 + 34*60 + 56.789));// positive assertEquals( "01:02:03", Time.writeTime( 1*3600 + 2*60 + 3.4)); // positive with leading zero assertEquals("-12:34:56", Time.writeTime(-12*3600 - 34*60 - 56.789)); // negative assertEquals("-01:02:03", Time.writeTime( -1*3600 - 2*60 - 3.4)); // negative with leading zero assertEquals( "00:00:00", Time.writeTime(0.0)); // zero /* Integer.MIN_VALUE is a special value in case time values would be represented by int's, and not double's. * Math.abs(Integer.MIN_VALUE) returns Integer.MIN_VALUE again, what could lead to a infinite loop depending * how negative times are handled internally. So this test should ensure this or a future implementation * does not have problems with that. */ assertEquals("-596523:14:08", Time.writeTime(Integer.MIN_VALUE)); }