I am trying to use a program called RaceRender to add the metadata from my GoPro to be included in my videos. There is a function to display the date and time and it generally works okay except for one day (31 Jan 2023) where the dates were reflecting as 3 Mar 2023. All my videos on 31 Jan 2023 are showing up as 3 Mar 2023.
Here is an example of the epoch data from my GoPro. I am definite that the data is correct and valid.
[](https://i.stack.imgur.com/XUZtP.png)
This was the code used in the program to convert the Epoch data to a human readable data:
MinuteSeconds = 60;
HourSeconds = 60 * MinuteSeconds;
DaySeconds = 24 * HourSeconds;
DaysPerYear = 365;
DaysPerLeapYear = DaysPerYear + 1;
DaysPerYearX4 = (DaysPerYear * 3) + DaysPerLeapYear;
BaseEpochSeconds = 946684800; // 00:00:00 Jan 1, 2000 UTC
BaseEpochYear = 2000; // This needs to be a leap year (ie divisible by 4)
// Convert UTC timestamp to number of seconds since the base epoch time, in the desired timezone
SecondsElapsed = (DataValue + TimeZoneShift) - BaseEpochSeconds;
if(SecondsElapsed < 0)
SecondsElapsed = 0; // Don't go before Jan 1 of our base epoch year
if(ShowDate)
{
DaysElapsed = floor(SecondsElapsed / DaySeconds);
YearsElapsedX4 = floor(DaysElapsed / DaysPerYearX4);
DaysRemainingX4 = DaysElapsed - (YearsElapsedX4 * DaysPerYearX4);
YearsElapsed = YearsElapsedX4 * 4;
if(DaysRemainingX4 >= DaysPerLeapYear)
{
// Account for days in the leap year
YearsElapsed += 1;
DaysRemainingX4 -= DaysPerLeapYear;
}
// Account for days in the non-leap years
AddYears = floor(DaysRemainingX4 / DaysPerYear);
YearsElapsed += AddYears;
DaysRemainingX4 -= AddYears * DaysPerYear;
// Actual year and number of days into the year
Year = BaseEpochYear + YearsElapsed;
JulianDate = DaysRemainingX4 + 1;
IsLeapYear = ((Year % 4) == 0);
// Convert Julian Date into Month and Day
Month = 1;
MonthName = "January";
Day = JulianDate;
// After January
if(Day > 31)
{
Month += 1;
MonthName = "February";
Day -= 31;
}
// After February
if(IsLeapYear)
{
if(Day > 29)
{
Month += 1;
MonthName = "March";
Day -= 29;
}
}
else
{
if(Day > 28)
{
Month += 1;
MonthName = "March";
Day -= 28;
}
}
// After March
if(Day > 31)
{
Month += 1;
MonthName = "April";
Day -= 31;
}
// After April
if(Day > 30)
{
Month += 1;
MonthName = "May";
Day -= 30;
}
// After May
if(Day > 31)
{
Month += 1;
MonthName = "June";
Day -= 31;
}
// After June
if(Day > 30)
{
Month += 1;
MonthName = "July";
Day -= 30;
}
// After July
if(Day > 31)
{
Month += 1;
MonthName = "Augustl";
Day -= 31;
}
// After August
if(Day > 31)
{
Month += 1;
MonthName = "September";
Day -= 31;
}
// After September
if(Day > 30)
{
Month += 1;
MonthName = "October";
Day -= 30;
}
// After October
if(Day > 31)
{
Month += 1;
MonthName = "November";
Day -= 31;
}
// After November
if(Day > 30)
{
Month += 1;
MonthName = "December";
Day -= 30;
}
if(ShowDateISO)
{
// Format date as "YYYY-MM-DD"
MonthString = FormatNumber(Month, 0);
if(Month < 10)
MonthString = "0" + MonthString;
DayString = FormatNumber(Day, 0);
if(Day < 10)
DayString = "0" + DayString;
DateString = FormatNumber(Year, 0) + "-" + MonthString + "-" + DayString;
}
else // !ShowDateISO
DateString = SubStr(MonthName, 0, 3) + " " + FormatNumber(Day, 0) + ", " + FormatNumber(Year, 0);
}
else // !ShowDate
DateString = "";
How can this be fixed such that 31 Jan 2023 can be shown correctly? Thanks.
As i do not have any programming knowledge, I tried ChatGPT etc for help but it didn't help.
From ChatGPT's reply, it says:
The code provided seems to be an attempt to convert a UTC timestamp to a date string in a given timezone. However, there appears to be an error in the logic for determining the month and day.
In the code, the logic for determining the month and day relies on subtracting the number of days for each month from the remaining days until the desired date is reached. However, there's a logical flaw in the implementation, leading to incorrect month calculations.
Specifically, in the part of the code where it handles the month transitions, there's an issue when the day exceeds the number of days in a month. For instance, after January, the code simply subtracts 31 from the day to move to February. However, it doesn't account for the varying number of days in each month. This leads to incorrect month assignments.
Here's an example of the issue:
Suppose the input Julian date is 31, which corresponds to January 31st. After the code subtracts 31 days for January, it should recognize that the date falls in January and stop there. However, since it doesn't have logic to do so, it incorrectly continues into March, resulting in the incorrect date of March 3rd.
To fix this issue, you would need to adjust the logic for handling month transitions to properly account for the varying number of days in each month. One way to do this is by implementing a more robust algorithm for converting Julian dates to month and day. This could involve iterating through the months and subtracting the appropriate number of days until the correct month is identified.
