Re: What does mktime return????

2019-12-18 Thread Grant Gainey
On Wed, Dec 18, 2019 at 1:46 PM John Pilkington 
wrote:

> On 18/12/2019 15:12, Mark C. Allman wrote:
> >
> > The month value range is 0 to 11, not 1 to 12.  You're calculating
> > 12/30/2019 at 23:59:59 to 01/01/2020 at 00:00:00, or 86401 seconds.
> >
>
> This is in accord with 'man mktime' but it's certainly a trap for the
> unwary.  Calendar days are treated normally, but not months.  I wonder
> how many space probes have strayed or contracts misfired...
>

There are two hard things in computer science: cache invalidation, naming
things, and off-by-one errors. :)

 G
-- 
Grant Gainey
Principal Software Engineer, Red Hat System Management Engineering
___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org


Re: What does mktime return????

2019-12-18 Thread John Pilkington

On 18/12/2019 15:12, Mark C. Allman wrote:

On 12/18/19 9:17 AM, Jouk Jansen wrote:

Hi All,

I'm strugling with the C-function mktime. According to the man-pages it
returns "seconds  since  the Epoch". I tried to use this functions to get
differnces from two date-times , but was could not interpret the result.
When trying to get the diffrence between 30 Nov 2019 23:59:59 and 1 
Dec 2019
00:00:00 (see code below) I expected to find 1 second difference but I 
find:

    1577746799 1577833200 -86401
As output of the sample program. (and not 1577833199 1577833200 -1)

How should I read "seconds  since  the Epoch"
Is the output of mktime correct?
  (I also tried 31 Nov and got the expected 1 second)
  (should mktime not give an error for 31 Nov??)
  Regards
 Jouk





The month value range is 0 to 11, not 1 to 12.  You're calculating 
12/30/2019 at 23:59:59 to 01/01/2020 at 00:00:00, or 86401 seconds.




This is in accord with 'man mktime' but it's certainly a trap for the 
unwary.  Calendar days are treated normally, but not months.  I wonder 
how many space probes have strayed or contracts misfired...


Changing it now would cause yet more confusion.

John P
___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org


Re: EXTERNAL: Re: What does mktime return????

2019-12-18 Thread Wells, Roger K. via users
On 12/18/19 10:24 AM, Walter H. wrote:
Hello,

I tried your programme on my system (other linux distribution), and got the 
same result;
even on windows the same results;

but this is interesting

# date --date="Dec 1 00:00:00 2019" +"%s"
1575154800

# date --date="Nov 30 23:59:59 2019" +"%s"
1575154799

there you have this 1 second difference;

I'd say mktime seens to be buggy ...

Walter

On 18.12.2019 15:17, Jouk Jansen wrote:
Hi All,

I'm strugling with the C-function mktime. According to the man-pages it
returns "seconds  since  the Epoch". I tried to use this functions to get
differnces from two date-times , but was could not interpret the result.
When trying to get the diffrence between 30 Nov 2019 23:59:59 and 1 Dec 2019
00:00:00 (see code below) I expected to find 1 second difference but I find:
1577746799 1577833200 -86401
As output of the sample program. (and not 1577833199 1577833200 -1)

How should I read "seconds  since  the Epoch"
Is the output of mktime correct?
  (I also tried 31 Nov and got the expected 1 second)
  (should mktime not give an error for 31 Nov??)



  Regards
 Jouk






Code :


#include
#include

main()
{
struct tm time_str , time_str2;

time_str.tm_sec = 59; //30 Nov 2019 23:59:59
time_str.tm_min = 59;
time_str.tm_hour = 23;
time_str.tm_mday = 30;
time_str.tm_mon = 11;
time_str.tm_year = 119;
time_str.tm_isdst = 0;

time_str2.tm_sec = 0; // 1 Dec 2019 00:00:00
time_str2.tm_min = 0;
time_str2.tm_hour = 0;
time_str2.tm_mday = 1;
time_str2.tm_mon = 12;
time_str2.tm_year = 119;
time_str2.tm_isdst = 0;

printf( "%d %d %d\n" , mktime(&time_str ) , mktime(&time_str2 ) ,
   mktime(&time_str ) - mktime(&time_str2 ) );

}


remember that the month values (tm_mon) go from 0 to 11.

change tm_mon for November to 10 and for December to 11 and you get the 
expected result.



___
users mailing list -- 
users@lists.fedoraproject.org
To unsubscribe send an email to 
users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org



--
Roger Wells, P.E.
leidos
221 Third St
Newport, RI 02840
401-847-4210 (voice)
401-849-1585 (fax)
roger.k.we...@leidos.com

___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org


Re: What does mktime return????

2019-12-18 Thread Walter H.

Hello,

I tried your programme on my system (other linux distribution), and got 
the same result;

even on windows the same results;

but this is interesting

# date --date="Dec 1 00:00:00 2019" +"%s"
1575154800

# date --date="Nov 30 23:59:59 2019" +"%s"
1575154799

there you have this 1 second difference;

I'd say mktime seens to be buggy ...

Walter

On 18.12.2019 15:17, Jouk Jansen wrote:

Hi All,

I'm strugling with the C-function mktime. According to the man-pages it
returns "seconds  since  the Epoch". I tried to use this functions to get
differnces from two date-times , but was could not interpret the result.
When trying to get the diffrence between 30 Nov 2019 23:59:59 and 1 Dec 2019
00:00:00 (see code below) I expected to find 1 second difference but I find:
1577746799 1577833200 -86401
As output of the sample program. (and not 1577833199 1577833200 -1)

How should I read "seconds  since  the Epoch"
Is the output of mktime correct?
  (I also tried 31 Nov and got the expected 1 second)
  (should mktime not give an error for 31 Nov??)



  Regards
 Jouk






Code :


#include
#include

main()
{
struct tm time_str , time_str2;

time_str.tm_sec = 59; //30 Nov 2019 23:59:59
time_str.tm_min = 59;
time_str.tm_hour = 23;
time_str.tm_mday = 30;
time_str.tm_mon = 11;
time_str.tm_year = 119;
time_str.tm_isdst = 0;

time_str2.tm_sec = 0; // 1 Dec 2019 00:00:00
time_str2.tm_min = 0;
time_str2.tm_hour = 0;
time_str2.tm_mday = 1;
time_str2.tm_mon = 12;
time_str2.tm_year = 119;
time_str2.tm_isdst = 0;

printf( "%d %d %d\n" , mktime(&time_str ) , mktime(&time_str2 ) ,
   mktime(&time_str ) - mktime(&time_str2 ) );

}




smime.p7s
Description: S/MIME Cryptographic Signature
___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org


Re: What does mktime return????

2019-12-18 Thread Mark C. Allman

On 12/18/19 9:17 AM, Jouk Jansen wrote:

Hi All,

I'm strugling with the C-function mktime. According to the man-pages it
returns "seconds  since  the Epoch". I tried to use this functions to get
differnces from two date-times , but was could not interpret the result.
When trying to get the diffrence between 30 Nov 2019 23:59:59 and 1 Dec 2019
00:00:00 (see code below) I expected to find 1 second difference but I find:
1577746799 1577833200 -86401
As output of the sample program. (and not 1577833199 1577833200 -1)

How should I read "seconds  since  the Epoch"
Is the output of mktime correct?
  (I also tried 31 Nov and got the expected 1 second)
  (should mktime not give an error for 31 Nov??)
  
  
  
  Regards

 Jouk






Code :


#include 
#include 

main()
{
struct tm time_str , time_str2;

time_str.tm_sec = 59; //30 Nov 2019 23:59:59
time_str.tm_min = 59;
time_str.tm_hour = 23;
time_str.tm_mday = 30;
time_str.tm_mon = 11;
time_str.tm_year = 119;
time_str.tm_isdst = 0;

time_str2.tm_sec = 0; // 1 Dec 2019 00:00:00

time_str2.tm_min = 0;
time_str2.tm_hour = 0;
time_str2.tm_mday = 1;
time_str2.tm_mon = 12;
time_str2.tm_year = 119;
time_str2.tm_isdst = 0;

printf( "%d %d %d\n" , mktime( &time_str ) , mktime( &time_str2 ) ,
   mktime( &time_str ) - mktime( &time_str2 ) );

}







Pax, vel iniusta, utilior est quam iustissimum bellum.
 (free after Marcus Tullius Cicero (106 b.Chr.-46 b.Chr.)
  Epistularum ad Atticum 7.1.4.3)


Touch not the cat bot a glove


--<

   Jouk Jansen

   jo...@hrem.nano.tudelft.nl

   Technische Universiteit Delfttt  uu uu  ddd
   Kavli Institute of Nanoscience   tt  uu uu  dddd
   Nationaal centrum voor HREM  tt  uu uu  dd dd
   Lorentzweg 1 tt  uu uu  dd dd
   2628 CJ Delfttt  uu uu  dd dd
   Nederlandtt  uu uu  dddd
   tel. 31-15-2782272   tt   uuu   ddd


--<



The month value range is 0 to 11, not 1 to 12.  You're calculating 
12/30/2019 at 23:59:59 to 01/01/2020 at 00:00:00, or 86401 seconds.



*Mark C. Allman, PMP, CSM*
Founder, See How You Ski, www.seehowyouski.com 
Sr. Project Manager, Allman Professional Consulting, Inc., 
www.allmanpc.com 

617-947-4263, Twitter: @allmanpc

___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org


What does mktime return????

2019-12-18 Thread Jouk Jansen
Hi All,

I'm strugling with the C-function mktime. According to the man-pages it
returns "seconds  since  the Epoch". I tried to use this functions to get
differnces from two date-times , but was could not interpret the result.
When trying to get the diffrence between 30 Nov 2019 23:59:59 and 1 Dec 2019
00:00:00 (see code below) I expected to find 1 second difference but I find:
   1577746799 1577833200 -86401
As output of the sample program. (and not 1577833199 1577833200 -1)

How should I read "seconds  since  the Epoch"
Is the output of mktime correct?
 (I also tried 31 Nov and got the expected 1 second)
 (should mktime not give an error for 31 Nov??)
 
 
 
 Regards
 Jouk






Code :


#include 
#include 

main()
{
   struct tm time_str , time_str2;

   time_str.tm_sec = 59; //30 Nov 2019 23:59:59
   time_str.tm_min = 59;
   time_str.tm_hour = 23;
   time_str.tm_mday = 30;
   time_str.tm_mon = 11;
   time_str.tm_year = 119;
   time_str.tm_isdst = 0;
   
   time_str2.tm_sec = 0; // 1 Dec 2019 00:00:00
   time_str2.tm_min = 0;
   time_str2.tm_hour = 0;
   time_str2.tm_mday = 1;
   time_str2.tm_mon = 12;
   time_str2.tm_year = 119;
   time_str2.tm_isdst = 0;

   printf( "%d %d %d\n" , mktime( &time_str ) , mktime( &time_str2 ) ,
   mktime( &time_str ) - mktime( &time_str2 ) );

}







Pax, vel iniusta, utilior est quam iustissimum bellum.
(free after Marcus Tullius Cicero (106 b.Chr.-46 b.Chr.)
 Epistularum ad Atticum 7.1.4.3)


   Touch not the cat bot a glove

>--<

  Jouk Jansen
 
  jo...@hrem.nano.tudelft.nl

  Technische Universiteit Delfttt  uu uu  ddd
  Kavli Institute of Nanoscience   tt  uu uu  dddd
  Nationaal centrum voor HREM  tt  uu uu  dd dd
  Lorentzweg 1 tt  uu uu  dd dd
  2628 CJ Delfttt  uu uu  dd dd
  Nederlandtt  uu uu  dddd
  tel. 31-15-2782272   tt   uuu   ddd

>--<
___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org