[1622] | 1 | #include "xios.hpp" |
---|
| 2 | |
---|
[794] | 3 | #include "icutil.hpp" |
---|
[545] | 4 | #include "icdate.hpp" |
---|
| 5 | #include "calendar_util.hpp" |
---|
| 6 | |
---|
| 7 | extern "C" |
---|
| 8 | { |
---|
[794] | 9 | void cxios_duration_convert_to_string(cxios_duration dur_c, char* str, int str_size) |
---|
[1622] | 10 | TRY |
---|
[794] | 11 | { |
---|
[1472] | 12 | xios::CDuration dur( dur_c.year, dur_c.month, dur_c.day, dur_c.hour, dur_c.minute, dur_c.second, dur_c.timestep ); |
---|
[794] | 13 | |
---|
| 14 | if (!string_copy(dur.toString(), str, str_size)) |
---|
| 15 | ERROR("void cxios_duration_convert_to_string(cxios_duration dur_c, char* str, int str_size)", << "Input string is too short"); |
---|
| 16 | } |
---|
[1622] | 17 | CATCH_DUMP_STACK |
---|
[794] | 18 | |
---|
[801] | 19 | cxios_duration cxios_duration_convert_from_string(const char* str, int str_size) |
---|
[1622] | 20 | TRY |
---|
[801] | 21 | { |
---|
| 22 | std::string dur_str; |
---|
| 23 | xios::CDuration dur; |
---|
| 24 | |
---|
| 25 | if (cstr2string(str, str_size, dur_str)) |
---|
| 26 | dur = xios::CDuration::FromString(dur_str); |
---|
| 27 | |
---|
| 28 | return { dur.year, dur.month, dur.day, dur.hour, dur.minute, dur.second, dur.timestep }; |
---|
| 29 | } |
---|
[1622] | 30 | CATCH_DUMP_STACK |
---|
[801] | 31 | |
---|
[545] | 32 | cxios_duration cxios_duration_add(cxios_duration dur1_c, cxios_duration dur2_c) |
---|
[1622] | 33 | TRY |
---|
[545] | 34 | { |
---|
[1472] | 35 | xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep ); |
---|
| 36 | xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep ); |
---|
| 37 | |
---|
[545] | 38 | xios::CDuration res = dur1 + dur2; |
---|
| 39 | return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep }; |
---|
| 40 | } |
---|
[1622] | 41 | CATCH_DUMP_STACK |
---|
[545] | 42 | |
---|
| 43 | cxios_duration cxios_duration_sub(cxios_duration dur1_c, cxios_duration dur2_c) |
---|
[1622] | 44 | TRY |
---|
[545] | 45 | { |
---|
[1472] | 46 | xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep ); |
---|
| 47 | xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep ); |
---|
| 48 | |
---|
[545] | 49 | xios::CDuration res = dur1 - dur2; |
---|
| 50 | return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep }; |
---|
| 51 | } |
---|
[1622] | 52 | CATCH_DUMP_STACK |
---|
[545] | 53 | |
---|
| 54 | cxios_duration cxios_duration_mult(double val, cxios_duration dur_c) |
---|
[1622] | 55 | TRY |
---|
[545] | 56 | { |
---|
[1472] | 57 | xios::CDuration dur( dur_c.year, dur_c.month, dur_c.day, dur_c.hour, dur_c.minute, dur_c.second, dur_c.timestep ); |
---|
[545] | 58 | xios::CDuration res = val * dur; |
---|
| 59 | return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep }; |
---|
| 60 | } |
---|
[1622] | 61 | CATCH_DUMP_STACK |
---|
[545] | 62 | |
---|
| 63 | cxios_duration cxios_duration_neg(cxios_duration dur_c) |
---|
[1622] | 64 | TRY |
---|
[545] | 65 | { |
---|
[1472] | 66 | xios::CDuration dur( dur_c.year, dur_c.month, dur_c.day, dur_c.hour, dur_c.minute, dur_c.second, dur_c.timestep ); |
---|
[545] | 67 | xios::CDuration res = -dur; |
---|
| 68 | return { res.year, res.month, res.day, res.hour, res.minute, res.second, res.timestep }; |
---|
| 69 | } |
---|
[1622] | 70 | CATCH_DUMP_STACK |
---|
[545] | 71 | |
---|
| 72 | bool cxios_duration_eq(cxios_duration dur1_c, cxios_duration dur2_c) |
---|
[1622] | 73 | TRY |
---|
[545] | 74 | { |
---|
[1472] | 75 | xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep ); |
---|
| 76 | xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep ); |
---|
[545] | 77 | return (dur1 == dur2); |
---|
| 78 | } |
---|
[1622] | 79 | CATCH_DUMP_STACK |
---|
[545] | 80 | |
---|
| 81 | bool cxios_duration_neq(cxios_duration dur1_c, cxios_duration dur2_c) |
---|
[1622] | 82 | TRY |
---|
[545] | 83 | { |
---|
[1472] | 84 | xios::CDuration dur1( dur1_c.year, dur1_c.month, dur1_c.day, dur1_c.hour, dur1_c.minute, dur1_c.second, dur1_c.timestep ); |
---|
| 85 | xios::CDuration dur2( dur2_c.year, dur2_c.month, dur2_c.day, dur2_c.hour, dur2_c.minute, dur2_c.second, dur2_c.timestep ); |
---|
[545] | 86 | return (dur1 != dur2); |
---|
| 87 | } |
---|
[1622] | 88 | CATCH_DUMP_STACK |
---|
[1472] | 89 | } |
---|