Results 1 to 3 of 3

Thread: Date and Time Object - wrong date being reflected for all videos on 31 Jan

  1. #1
    Potential Tuner
    Join Date
    Mar 2024
    Posts
    2

    Date and Time Object - wrong date being reflected for all videos on 31 Jan

    Hi all

    I am using the Date and Time object and whilst it works fine for most dates, it looks like all videos with 31 Jan 2023 are coming up as 3 Mar 2023. It looks like the logic to calculate the epoch date is wrong. Would anyone be able to help me out as I cannot figure out what is wrong with the code?

    I am sure the GoPro data is correct as the Raw epoch data are:

    1675151208
    1675151210
    1675151211
    1675151211

    // 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 = "August";
    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 = "";

  2. #2
    Advanced Tuner
    Join Date
    Apr 2018
    Posts
    296
    Try using the "_Timer - Date and Time - Updated.rro" display object mentioned in this post: https://forum.hptuners.com/showthrea...l=1#post608727

    I think I had found that the date logic would still try to act on the day even after the correct month had been found; so I added some additional logic to essentially stop looking at the next month once we had found the correct month.

  3. #3
    Potential Tuner
    Join Date
    Mar 2024
    Posts
    2
    Thank you very much, HoboBob! It looks to display the right date now.