Skip to content

Commit 62ec779

Browse files
committed
Change output time and date formats to ISO 8601 standards
1 parent 1e91cc0 commit 62ec779

File tree

1 file changed

+13
-58
lines changed

1 file changed

+13
-58
lines changed

dhandler.c

+13-58
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,7 @@ void PrintRTData(bool includeLoop2Data)
594594
/**
595595
* Converts a BCD encoded time value to ascii human readable form. Returns
596596
* a pointer to a static buffer containing the converted ascii string. The
597-
* form is '12:33PM'. If you don't like this format, here is where you need
598-
* to change it.
597+
* form is in the ISO 8601 format.
599598
*
600599
* @param wTime Time integer to convert
601600
*
@@ -604,7 +603,6 @@ void PrintRTData(bool includeLoop2Data)
604603
char* TimeConvert(uint16_t wTime)
605604
{
606605
static char szBuf[32]; /* static return buffer */
607-
bool bAM = true;
608606
int nHours = wTime/100;
609607
int nMinutes = wTime - ((wTime/100) * 100);
610608

@@ -615,22 +613,7 @@ char* TimeConvert(uint16_t wTime)
615613
return szBuf;
616614
}
617615

618-
if(nHours > 12)
619-
{
620-
/* PM time ? */
621-
nHours -= 12;
622-
bAM = false;
623-
}
624-
else if(nHours == 12)
625-
bAM = false;
626-
627-
if(nHours == 0 && bAM)
628-
nHours = 12;
629-
if(nMinutes)
630-
sprintf(szBuf, "%d:%02d%s", nHours, nMinutes, (bAM?"AM":"PM"));
631-
else
632-
sprintf(szBuf, "%d%s", nHours, (bAM?"AM":"PM"));
633-
616+
sprintf(szBuf, "%02d:%02d", nHours, nMinutes);
634617

635618
return szBuf;
636619
}
@@ -639,8 +622,7 @@ char* TimeConvert(uint16_t wTime)
639622

640623

641624
/**
642-
* Prints an encoded date value in the form '23-JUN-04'. If you don't like
643-
* this format, here is where you need to do your hacking.
625+
* Prints an encoded date value in the ISO 8601 format.
644626
*
645627
* @param wDate Date integer to convert
646628
*/
@@ -652,29 +634,17 @@ void PrintDate(uint16_t wDate)
652634
printf("n/a");
653635
return;
654636
}
637+
// Year
638+
printf("20%02d-", (wDate & 0x003f) );
639+
640+
// Month
641+
printf("%02d-", (wDate & 0xf000) >> 12); /* strip out month */
642+
643+
// Day
655644
w = (wDate & 0x0f00) >> 7; /* get msb of date */
656645
if(wDate & 0x0080)
657646
++w; /* do crappy Davis format incr */
658-
printf("%02d-", w);
659-
660-
w = (wDate & 0xf000) >> 12; /* strip out month */
661-
switch(w) {
662-
case 1: printf("JAN"); break;
663-
case 2: printf("FEB"); break;
664-
case 3: printf("MAR"); break;
665-
case 4: printf("APR"); break;
666-
case 5: printf("MAY"); break;
667-
case 6: printf("JUN"); break;
668-
case 7: printf("JUL"); break;
669-
case 8: printf("AUG"); break;
670-
case 9: printf("SEP"); break;
671-
case 10: printf("OCT"); break;
672-
case 11: printf("NOV"); break;
673-
case 12: printf("DEC"); break;
674-
default: printf("???"); break;
675-
}
676-
677-
printf("-20%02d", (wDate & 0x003f) );
647+
printf("%02d", w);
678648
}
679649

680650

@@ -749,7 +719,7 @@ void PrintTimeRef(void)
749719
stm.tm_mday -= i; /* back by days */
750720
tt = mktime(&stm);
751721
stm = *localtime(&tt); /* get time again */
752-
printf("%d/%d", stm.tm_mon+1, stm.tm_mday);
722+
printf("%4d-%02d-%02d", stm.tm_year + 1900, stm.tm_mon+1, stm.tm_mday);
753723
if(i > 1)
754724
printf(",");
755725
}
@@ -761,22 +731,7 @@ void PrintTimeRef(void)
761731
stm = *localtime(&tt); /* get time now */
762732
for(i = 24; i; i--)
763733
{
764-
switch(stm.tm_mon)
765-
{
766-
case 0: printf("JAN"); break;
767-
case 1: printf("FEB"); break;
768-
case 2: printf("MAR"); break;
769-
case 3: printf("APR"); break;
770-
case 4: printf("MAY"); break;
771-
case 5: printf("JUN"); break;
772-
case 6: printf("JUL"); break;
773-
case 7: printf("AUG"); break;
774-
case 8: printf("SEP"); break;
775-
case 9: printf("OCT"); break;
776-
case 10: printf("NOV"); break;
777-
case 11: printf("DEC"); break;
778-
default: printf("???"); break;
779-
}
734+
printf("%d", stm.tm_mon + 1);
780735
stm.tm_mon++;
781736
if (stm.tm_mon > 11) stm.tm_mon = 0;
782737

0 commit comments

Comments
 (0)