//<RTCC>
typedef struct DateTime {
  char Year, Month, Day, Hour, Minute, Second;
} TDateTime;
//</RTCC>

void RTCC_GenerateDigits(char value, char *pos) {
  *pos = (value / 10) + 48;
  pos++;
  *pos = (value % 10) + 48;
}

void RTCC_GenerateDateStringYMD(TDateTime *dt, char *rtccstring) {
  // YY-MM-DD
  char *pos;
  char sep = '-';
  pos = rtccstring;
  RTCC_GenerateDigits((*dt).Year, pos);
  pos += 2; *pos = sep; pos++;
  RTCC_GenerateDigits((*dt).Month, pos);
  pos += 2; *pos = sep; pos++;
  RTCC_GenerateDigits((*dt).Day, pos);
  pos += 2; 
  *pos = 0;
}   

void RTCC_GenerateDateStringDMY(TDateTime *dt, char *rtccstring) {
  // DD/MM/YYYY
  char *pos;
  char sep = '/';
  pos = rtccstring;
  RTCC_GenerateDigits((*dt).Day, pos);
  pos += 2; *pos = sep; pos++;
  RTCC_GenerateDigits((*dt).Month, pos);
  pos += 2; *pos = sep; pos++;
  *pos = '2'; pos++;
  *pos = '0'; pos++;
  RTCC_GenerateDigits((*dt).Year, pos);
  pos += 2; 
  *pos = 0;
}

void RTCC_GenerateTimeString(TDateTime *dt, char *rtccstring, char incl_sec) {
  // hh:mm or hh:mm:ss
  char *pos;
  pos = rtccstring;
  RTCC_GenerateDigits((*dt).Hour, pos);
  pos += 2; *pos = ':'; pos++;
  RTCC_GenerateDigits((*dt).Minute, pos);
  if (incl_sec) {
    pos += 2; *pos = ':'; pos++;
    RTCC_GenerateDigits((*dt).Second, pos);
  }
  pos += 2;
  *pos = 0;
}

void RTCC_GenerateString(TDateTime *dt, char *rtccstring) { 
  RTCC_GenerateDateStringDMY(dt, rtccstring);
  rtccstring[10] = ' ';
  RTCC_GenerateTimeString(dt, rtccstring + 11, 0);
}