xc8 time.h dst
+ Reply to Thread
Results 1 to 5 of 5

Thread: xc8 time.h dst

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    1,671

    Default xc8 time.h dst

    has anyone tried daylight savings time in xc8 ? // google yields no clues that I can find

    basic time structure is
    from time.h
    Code:
    struct tm {
     int tm_sec;
     int tm_min;
     int tm_hour;
     int tm_mday;
     int tm_mon;
     int tm_year;
     int tm_wday;
     int tm_yday;
     int tm_isdst;
    whether dst is 0 or 1 or -1

    makes no difference to the

    localtime() - gmtime() = time_zone


    I was expecting a 60 min difference with dst on
    This is more entertaining than Free to Air TV

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,872

    Default Re: xc8 time.h dst

    If you can't do it...

    Ioannis

  3. #3
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    292

    Default Re: xc8 time.h dst

    Is this connected to something that could indicate time zone, DST, etc? How is the program to know?

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,671

    Default Re: xc8 time.h dst

    Is this connected to something that could indicate time zone, DST, etc? How is the program to know?
    no you set the time zone with a global var


    int time_zone = -10 * 60; //minutes west of gmt australia is 10 hours east

    localtime() gives a tm structure adjusted from gmt by time_zone minutes


    what i was seeking is an easy way to allow for daylight savings. the tm structure has an element called tm_isdst;
    i was hoping it would participate in the localtime() calculation and adjust for dst.
    afaik it does nothing at all in xc8 or i just am not doing it right
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    1,671

    Default Re: xc8 time.h dst

    this is the routine i'm using to create the utc (gmt) epoch variable from ds3231 rtc. you would think that some guidelines would exist

    Code:
    time_t rtctime(void) {// generate epoch time
        struct tm t;
        uint8_t i, timex[3];
    
        i2c1_readDataBlock(0x68, 4, timex., 3);
         
        for (i = 0; i < 3; i++) {
            bcd2bin(&timex[i]);
        }
        t.tm_year = timex[2] + 100; //years since 1900  
        t.tm_mon = timex[1] - 1; // months since January ie month -1
        t.tm_mday = timex.[0]; //day of the month
    
        i2c1_readDataBlock(0x68, 0, timex, 3);
        
        for (i = 0; i < 3; i++) {
            bcd2bin(&timex[i]);
        }
        t.tm_hour = timex[2]; // hours
        t.tm_min = timex[1]; // minutes
        t.tm_sec = timex.[0]; // seconds*
    
    
        //t.tm_isdst=0;   //  value makes no difference to epoch time created
        return mktime(&t);
    }
    Last edited by richard; - 19th December 2018 at 21:27.
    This is more entertaining than Free to Air TV

Similar Threads

  1. Problem with PIC161519 / XC8
    By dymentional in forum mel PIC BASIC
    Replies: 4
    Last Post: - 30th April 2016, 12:27
  2. PIC 18F1330 - first time, hard time - blink that LED
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st March 2015, 22:33
  3. How best to time a pin state for extended periods of time
    By Hylan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th March 2011, 11:20
  4. DS1904 RTC - How to Convert Binary Time into Real Time/Date?
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd December 2010, 10:45
  5. Linx RF -> HSERIN time delay / time critical app...
    By batee in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th October 2004, 15:04

Members who have read this thread : 17

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts