577 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm", days.quot, hours.quot, minuts.quot); |
577 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm", days.quot, hours.quot, minuts.quot); |
578 }else{ |
578 }else{ |
579 if(IN.tv_nsec == 0){ |
579 if(IN.tv_nsec == 0){ |
580 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm%ds", days.quot, hours.quot, minuts.quot, minuts.rem); |
580 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm%ds", days.quot, hours.quot, minuts.quot, minuts.rem); |
581 }else{ |
581 }else{ |
582 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm%ds%gms", days.quot, hours.quot, minuts.quot, minuts.rem, IN.tv_nsec / 1000000); |
582 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "T#%dd%dh%dm%ds%gms", days.quot, hours.quot, minuts.quot, minuts.rem, (LREAL)IN.tv_nsec / 1000000); |
583 } |
583 } |
584 } |
584 } |
585 } |
585 } |
586 } |
586 } |
587 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
587 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
590 static inline STRING __date_to_string(DATE IN){ |
590 static inline STRING __date_to_string(DATE IN){ |
591 /* D#1984-06-25 */ |
591 /* D#1984-06-25 */ |
592 STRING res = __INIT_STRING; |
592 STRING res = __INIT_STRING; |
593 struct tm broken_down_time; |
593 struct tm broken_down_time; |
594 time_t seconds = IN.tv_sec; |
594 time_t seconds = IN.tv_sec; |
595 if (NULL == gmtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ |
595 if (NULL == localtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ |
596 IEC_error(); |
596 IEC_error(); |
597 return (STRING){7,"D#ERROR"}; |
597 return (STRING){7,"D#ERROR"}; |
598 } |
598 } |
599 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "D#%d-%2.2d-%2.2d", broken_down_time.tm_year, broken_down_time.tm_mon, broken_down_time.tm_mday); |
599 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "D#%d-%2.2d-%2.2d", broken_down_time.tm_year + 1900, broken_down_time.tm_mon + 1, broken_down_time.tm_mday); |
600 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
600 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
601 return res; |
601 return res; |
602 } |
602 } |
603 static inline STRING __tod_to_string(TOD IN){ |
603 static inline STRING __tod_to_string(TOD IN){ |
604 /* TOD#15:36:55.36 */ |
604 /* TOD#15:36:55.36 */ |
605 STRING res = __INIT_STRING; |
605 STRING res = __INIT_STRING; |
606 struct tm broken_down_time; |
606 struct tm broken_down_time; |
607 time_t seconds = IN.tv_sec; |
607 time_t seconds = IN.tv_sec; |
608 if (NULL == gmtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ |
608 if (NULL == localtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ |
609 IEC_error(); |
609 IEC_error(); |
610 return (STRING){9,"TOD#ERROR"}; |
610 return (STRING){9,"TOD#ERROR"}; |
611 } |
611 } |
612 if(IN.tv_nsec == 0){ |
612 if(IN.tv_nsec == 0){ |
613 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "TOD#%2.2d:%2.2d:%d", broken_down_time.tm_hour, broken_down_time.tm_min, broken_down_time.tm_sec); |
613 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "TOD#%2.2d:%2.2d:%d", broken_down_time.tm_hour, broken_down_time.tm_min, broken_down_time.tm_sec); |
614 }else{ |
614 }else{ |
615 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "TOD#%2.2d:%2.2d:%g", broken_down_time.tm_hour, broken_down_time.tm_min, (LREAL)broken_down_time.tm_sec + (LREAL)IN.tv_nsec / 1000000); |
615 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "TOD#%2.2d:%2.2d:%g", broken_down_time.tm_hour, broken_down_time.tm_min, (LREAL)broken_down_time.tm_sec + (LREAL)IN.tv_nsec / 1e9); |
616 } |
616 } |
617 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
617 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
618 return res; |
618 return res; |
619 } |
619 } |
620 static inline STRING __dt_to_string(DT IN){ |
620 static inline STRING __dt_to_string(DT IN){ |
621 /* DT#1984-06-25-15:36:55.36 */ |
621 /* DT#1984-06-25-15:36:55.36 */ |
622 STRING res; |
622 STRING res; |
623 struct tm broken_down_time; |
623 struct tm broken_down_time; |
624 time_t seconds = IN.tv_sec; |
624 time_t seconds = IN.tv_sec; |
625 if (NULL == gmtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ |
625 if (NULL == localtime_r(&seconds, &broken_down_time)){ /* get the UTC (GMT) broken down time */ |
626 IEC_error(); |
626 IEC_error(); |
627 return (STRING){8,"DT#ERROR"}; |
627 return (STRING){8,"DT#ERROR"}; |
628 } |
628 } |
629 if(IN.tv_nsec == 0){ |
629 if(IN.tv_nsec == 0){ |
630 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "DT#%d-%2.2d-%2.2d-%2.2d:%2.2d:%d", |
630 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "DT#%d-%2.2d-%2.2d-%2.2d:%2.2d:%d", |
633 broken_down_time.tm_mday, |
633 broken_down_time.tm_mday, |
634 broken_down_time.tm_hour, |
634 broken_down_time.tm_hour, |
635 broken_down_time.tm_min, |
635 broken_down_time.tm_min, |
636 broken_down_time.tm_sec); |
636 broken_down_time.tm_sec); |
637 }else{ |
637 }else{ |
638 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "DT#%d-%2.2d-%2.2d-%2.2d:%2.2d:%d", |
638 res.len = snprintf((char*)&res.body, STR_MAX_LEN, "DT#%d-%2.2d-%2.2d-%2.2d:%2.2d:%g", |
639 broken_down_time.tm_year, |
639 broken_down_time.tm_year, |
640 broken_down_time.tm_mon, |
640 broken_down_time.tm_mon, |
641 broken_down_time.tm_mday, |
641 broken_down_time.tm_mday, |
642 broken_down_time.tm_hour, |
642 broken_down_time.tm_hour, |
643 broken_down_time.tm_min, |
643 broken_down_time.tm_min, |
644 (LREAL)broken_down_time.tm_sec + ((LREAL)IN.tv_nsec / 1000000)); |
644 (LREAL)broken_down_time.tm_sec + ((LREAL)IN.tv_nsec / 1e9)); |
645 } |
645 } |
646 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
646 if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; |
647 return res; |
647 return res; |
648 } |
648 } |
649 /* BCD */ |
649 /* BCD */ |