• AVR Freaks

C30 Mktime() further than 2021 timestamp returns error -1.

Author
japeral
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2009/09/04 03:37:38
  • Location: Spain
  • Status: offline
2012/05/17 00:35:24 (permalink)
2 (1)

C30 Mktime() further than 2021 timestamp returns error -1.

 Hi,
 
I having problems with C30 compiler mktime() function.
 
If put 2020(120)/dec/31 23:59:59 GMT+1 in compiler's mktime() it returns epoch_seconds=1609459199
that is OK I have verified it in www.epochconverter.com
 
But, if I put 2021/jan/01 00:00:00 GMT+1 (on second later) it returns 4294967295 that is wrong result.
 
Could somebody give some help about this? I need more than 2020 working timestamp.
 
Because mktime is a precompiled function, I can't see what is happening inside function.
 
Could somebody send me mktime() source in C30?
 
Is this a known behaviour or library bug?
 
Thank you and best regards.
 

Aditional info about usage of mktime function is found in page 146 of 16-Bit_Language_Tools_Libraries_51456E.pdf
 
mktime
Description:
Converts local time to a calendar value.
Include: <time.h>
Prototype: time_t mktime(struct tm *tptr);
Argument: tptr a pointer to the time structure
Return Value: Returns the calendar time encoded as a value of time_t.
Remarks: If the calendar time cannot be represented, the function returns -1, castas a time_t (i.e. (time_t) -1).
 
post edited by japeral - 2012/05/17 09:28:31
#1

4 Replies Related Threads

    aschen0866
    Super Member
    • Total Posts : 4593
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re:C30 Mktime() further than 2021 timestamp error 2012/05/17 07:52:12 (permalink)
    0
    I am not sure if this is a known issue but I tested mktime() with C30 v3.30b and I did get incorrect result.  Here is my test code:

    #include <time.h>
    struct tm my_time =
    {
    /*
     *   int tm_sec;    // seconds after the minute ( 0 to 61 )       
     *                  // allows for up to two leap seconds          
     *   int tm_min;    // minutes after the hour ( 0 to 59 )         
     *   int tm_hour;   // hours since midnight ( 0 to 23 )           
     *   int tm_mday;   // day of month ( 1 to 31 )                   
     *   int tm_mon;    // month ( 0 to 11 where January = 0 )        
     *   int tm_year;   // years since 1900                           
     *   int tm_wday;   // day of week ( 0 to 6 where Sunday = 0 )    
     *   int tm_yday;   // day of year ( 0 to 365 where January 1 = 0 )
     *   int tm_isdst;  // Daylight Savings Time flag                 
     */
       .tm_sec = 0,
       .tm_min = 0,
       .tm_hour = 0,
       .tm_mday = 1,
       .tm_mon = 0,
       .tm_year = 2021 - 1900, /* 2020 ok, 2021 error */
       .tm_wday = 5,
       .tm_yday = 0,
       .tm_isdst = 0,
    };

    int main(void)
    {
       time_t t32;
       struct tm my_time_2;

       /* Year 2021: t32 = 0xFFFFFFFF
        * Year 2020: t32 = 0x5E0BE100
        */
       t32 = mktime(&my_time);

       my_time_2 = *localtime(&t32);

       while (1);
       return(0);
    }

    #2
    japeral
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2009/09/04 03:37:38
    • Location: Spain
    • Status: offline
    Re:C30 Mktime() further than 2021 timestamp error 2012/05/22 01:00:59 (permalink)
    0
    My problem is not solved.
    My compiler version is:
    Language tool versions: pic30-as.exe v3.31, pic30-gcc.exe v3.31, pic30-ld.exe v3.31, pic30-ar.exe v3.31
     
    Mktime() Returns time_t that is singed long value so it will be affected by overflow in 2147483647d (half range).
     
    I think a 31th bit overflow will occur in Tue, 19 Jan 2038 03:14:07 GMT =2147483647d =0b01111111111111111111111111111111.
     
    But the question is: Why the Microchip C30 mktime() overflows before in 2020->2021 transition?
     
    Thank you.
     
     
     
    post edited by japeral - 2012/05/24 03:18:50
    #3
    aschen0866
    Super Member
    • Total Posts : 4593
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re:C30 Mktime() further than 2021 timestamp error 2012/05/22 06:53:41 (permalink)
    0
    You should report the problem to Microchip's Tech Support.  The same problem also exists in the C32 compiler. The library source code hasn't been made available to the general public, therefore only people from Microchip can give you a definitive answer.
    #4
    japeral
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2009/09/04 03:37:38
    • Location: Spain
    • Status: offline
    Re:C30 Mktime() further than 2021 timestamp returns error -1. 2012/06/04 01:55:31 (permalink)
    +1 (1)
    Microchip problem resolution:
     
    Hi,
    This issue is confirmed. As a workaround you may use the legacy c library. To use the legacy C lib, go to MPLAB IDE Menu ( Project- Build Options - Project). Choose the MPLAB LINK30 Tab, In the category choose Libraries. There you should find an option to check Legacy Libc.

    Our response should resolve your issue or kindly come back to us for further technical clarifications. 

    Thanks & regards,
     
    I think this will be useful for anyone with this issue like me.
     
    Best regards.
    #5
    Jump to:
    © 2021 APG vNext Commercial Version 4.5