in java/src/main/java/com/epam/deltix/containers/DateTimeHelper.java [46:103]
public static MutableString append(MutableString mutableString, long time) {
long year = 1970;
year += 4 * (time / (MILLI_FOR_DAY * (DAY_IN_FOUR_YEAR)));
time %= (MILLI_FOR_DAY * (DAY_IN_FOUR_YEAR));
for (int i = 0; i < 4; ++i) {
int leapYear = 0;
if (i == 2) leapYear = 1;
if (time >= MILLI_FOR_DAY * (365 + leapYear)) {
time -= MILLI_FOR_DAY * (365 + leapYear);
year++;
}
}
long month = 1;
for (int i = 0; i < 12; ++i) {
int dayInMonth = DAY_IN_MONTH[i];
if (i == 1 && year % 4 == 0) dayInMonth++;
if (time >= dayInMonth * MILLI_FOR_DAY) {
month++;
time -= dayInMonth * MILLI_FOR_DAY;
} else break;
}
long day = time / MILLI_FOR_DAY + 1;
time %= MILLI_FOR_DAY;
long hour = time / (60 * 60 * 1000);
time %= (60 * 60 * 1000);
long minute = time / (60 * 1000);
time %= 60000;
long seconds = time / 1000;
long milliseconds = time % 1000;
mutableString.append(year);
mutableString.append('-');
if (month < 10) mutableString.append('0');
mutableString.append(month);
mutableString.append('-');
if (day < 10) mutableString.append('0');
mutableString.append(day);
mutableString.append(' ');
if (hour < 10) mutableString.append('0');
mutableString.append(hour);
mutableString.append(':');
if (minute < 10) mutableString.append('0');
mutableString.append(minute);
mutableString.append(':');
if (seconds < 10) mutableString.append('0');
mutableString.append(seconds);
mutableString.append('.');
if (milliseconds < 100) mutableString.append('0');
if (milliseconds < 10) mutableString.append('0');
mutableString.append(milliseconds);
return mutableString;
}