1 /******************************************************************************* 2 3 Copyright: 4 Copyright (c) 2009-2016 dunnhumby Germany GmbH. 5 All rights reserved. 6 7 License: 8 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 9 Alternatively, this file may be distributed under the terms of the Tango 10 3-Clause BSD License (see LICENSE_BSD.txt for details). 11 12 *******************************************************************************/ 13 14 module ocean.time.Time_test; 15 16 import ocean.time.Time; 17 import ocean.core.Test; 18 import ocean.text.convert.Formatter; 19 import ocean.text.convert.DateTime_tango; 20 21 unittest 22 { 23 test(TimeSpan.zero > TimeSpan.min); 24 test(TimeSpan.max > TimeSpan.zero); 25 test(TimeSpan.max > TimeSpan.min); 26 test(TimeSpan.zero >= TimeSpan.zero); 27 test(TimeSpan.zero <= TimeSpan.zero); 28 test(TimeSpan.max >= TimeSpan.max); 29 test(TimeSpan.max <= TimeSpan.max); 30 test(TimeSpan.min >= TimeSpan.min); 31 test(TimeSpan.min <= TimeSpan.min); 32 33 test(TimeSpan.fromSeconds(50).seconds is 50); 34 test(TimeSpan.fromSeconds(5000).seconds is 5000); 35 test(TimeSpan.fromMinutes(50).minutes is 50); 36 test(TimeSpan.fromMinutes(5000).minutes is 5000); 37 test(TimeSpan.fromHours(23).hours is 23); 38 test(TimeSpan.fromHours(5000).hours is 5000); 39 test(TimeSpan.fromDays(6).days is 6); 40 test(TimeSpan.fromDays(5000).days is 5000); 41 42 test(TimeSpan.fromSeconds(50).time.seconds is 50); 43 test(TimeSpan.fromSeconds(5000).time.seconds is 5000 % 60); 44 test(TimeSpan.fromMinutes(50).time.minutes is 50); 45 test(TimeSpan.fromMinutes(5000).time.minutes is 5000 % 60); 46 test(TimeSpan.fromHours(23).time.hours is 23); 47 test(TimeSpan.fromHours(5000).time.hours is 5000 % 24); 48 49 auto tod = TimeOfDay (25, 2, 3, 4); 50 tod = tod.span.time; 51 test(tod.hours is 1); 52 test(tod.minutes is 2); 53 test(tod.seconds is 3); 54 test(tod.millis is 4); 55 } 56 57 // pretty time formatting 58 unittest 59 { 60 test!("==")( 61 format("{}", asPrettyStr(Time.epoch1970)), 62 "01/01/70 00:00:00" 63 ); 64 test!("==")( 65 format("{}", asPrettyStr(Time.epoch1970 + TimeSpan.fromDays(5))), 66 "01/06/70 00:00:00" 67 ); 68 } 69 70 // raw time 71 unittest 72 { 73 test!("==")( 74 format("{}", Time.epoch1970), 75 "{ ticks_: 621355968000000000 }" 76 ); 77 test!("==")( 78 format("{}", Time.epoch1970 + TimeSpan.fromDays(5)), 79 "{ ticks_: 621360288000000000 }" 80 ); 81 }