Test case R1021
Full test suiteDevice test case
Time/date functions and convertions
This test case it part of the test suite proposed for new devices.
Test case ID: R1021
Language: ST
tests2/t1021.st(* time-date related functions and conversions *) PROGRAM T1021 VAR dt1,dt2:DT; t1,t2 : TIME; tod1,tod2 : TOD; d1,d2 : DATE; s1,s2 : STRING; r1,r2 : REAL; lr1,lr2 : LREAL; di : DINT; dw : DWORD; END_VAR dt1 := DT#2015-04-28-00:18:19; tod1 := DT_TO_TOD(dt1); _GEB_ASSERT_(tod1 = TOD#00:18:19); d1 := DT_TO_DATE(dt1); _GEB_ASSERT_(d1 = DATE#2015-04-28); dt2 := CONCAT_DATE_TOD(d1,tod1); _GEB_ASSERT_(dt2 = dt1); t1 := TOD_TO_TIME(tod1); // 1099000 msecs _GEB_ASSERT_(t1 = TIME#18m19s); di := TIME_TO_DINT(t1); _GEB_ASSERT_(di = 1099000); dw := TIME_TO_DWORD(t1); // alias to TIME_TO_DINT _GEB_ASSERT_(dw = 1099000); t1 := DINT_TO_TIME(di); _GEB_ASSERT_(t1 = TIME#18m19s); tod2 := TIME_TO_TOD(t1); _GEB_ASSERT_(tod1 = tod2); r1 := TIME_TO_REAL(t1); _GEB_ASSERT_EQFLOAT_(r1, 1099000.0); t1 := ADD_TIME(t1, TIME#1d1h1m2s345ms); t1 := SUB_TIME(t1, TIME#1d1h1m); // t1 = 1101345 _GEB_ASSERT_( TIME_TO_DINT(t1) = DINT#1101345); tod2 := SUB_TOD_TIME(tod1, TIME#19s); _GEB_ASSERT_(tod2 = TOD#00:18:00); di:= DATE_TO_DINT(d1); // unix epoch 2015-04-28 = 16553 days _GEB_ASSERT_(di = 16553); d1:= DINT_TO_DATE(di); // _GEB_ASSERT_(d1 = DATE#2015-04-28); r1:= DATE_TO_REAL(d1); // unix epoch 2015-04-28 = 16553 days _GEB_ASSERT_EQFLOAT_(r1,16553.0); di:= DT_TO_DINT(dt1); // unix epoch secs 2015-04-28-00:18:19; _GEB_ASSERT_(di = 1430180299); dt2 := DINT_TO_DT(di); _GEB_ASSERT_(dt2 = dt1); r1:= DT_TO_REAL(dt1); // unix epoch secs 2015-04-28-00:18:19; _GEB_ASSERT_EQFLOAT_(r1, 1430180299.0); // _GEB_MSG_(s1); END_PROGRAM