Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17584 > unrolled thread

its quiet here - test

Started bybill <william@TechServSys.com>
First post2017-10-22 07:58 -0400
Last post2017-10-26 20:48 -0500
Articles 10 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  its quiet here - test bill <william@TechServSys.com> - 2017-10-22 07:58 -0400
    Re: its quiet here - test hah <hah@no.email.stupid.invalid> - 2017-10-22 15:31 -0500
      Re: its quiet here - test Luuk <luuk@invalid.lan> - 2017-10-24 10:12 +0200
        Re: its quiet here - test Mark Lloyd <not@mail.invalid> - 2017-10-24 17:01 -0500
          Re: its quiet here - test Luuk <luuk@invalid.lan> - 2017-10-26 11:51 +0200
            Re: its quiet here - test Mark Lloyd <not@mail.invalid> - 2017-10-26 12:02 -0500
              Days until Christmas (was: its quiet here - test) "Christoph M. Becker" <cmbecker69@arcor.de> - 2017-10-26 19:29 +0200
                Re: Days until Christmas Mark Lloyd <not@mail.invalid> - 2017-10-26 17:56 -0500
                  Re: Days until Christmas "Christoph M. Becker" <cmbecker69@arcor.de> - 2017-10-27 01:38 +0200
                    Re: Days until Christmas Mark Lloyd <not@mail.invalid> - 2017-10-26 20:48 -0500

#17584 — its quiet here - test

Frombill <william@TechServSys.com>
Date2017-10-22 07:58 -0400
Subjectits quiet here - test
Message-ID<osi15t$14b7$2@gioia.aioe.org>
its quiet here - test

[toc] | [next] | [standalone]


#17585

Fromhah <hah@no.email.stupid.invalid>
Date2017-10-22 15:31 -0500
Message-ID<ie7HB.22292$wT2.6774@fx22.iad>
In reply to#17584
On 10/22/2017 06:58 AM, bill wrote:
> its quiet here - test

<?php

print "on-topic test: ";
print ( mktime(0,0,0,12,25) - time() ) / 86400;
print ' days until Christmas';

?>

[toc] | [prev] | [next] | [standalone]


#17586

FromLuuk <luuk@invalid.lan>
Date2017-10-24 10:12 +0200
Message-ID<59eef5e9$0$797$e4fe514c@news.xs4all.nl>
In reply to#17585
On 22-10-17 22:31, hah wrote:
> On 10/22/2017 06:58 AM, bill wrote:
>> its quiet here - test
> 
> <?php
> 
> print "on-topic test: ";
> print ( mktime(0,0,0,12,25) - time() ) / 86400;
> print ' days until Christmas';
> 
> ?>

on-topic test: 61.617662037037 days until Christmas

would that not be too accurate?

[toc] | [prev] | [next] | [standalone]


#17587

FromMark Lloyd <not@mail.invalid>
Date2017-10-24 17:01 -0500
Message-ID<gLOHB.37370$Ov1.6569@fx30.iad>
In reply to#17586
On 10/24/2017 03:12 AM, Luuk wrote:
> On 22-10-17 22:31, hah wrote:
>> On 10/22/2017 06:58 AM, bill wrote:
>>> its quiet here - test
>>
>> <?php
>>
>> print "on-topic test: ";
>> print ( mktime(0,0,0,12,25) - time() ) / 86400;
>> print ' days until Christmas';
>>
>> ?>
> 
> on-topic test: 61.617662037037 days until Christmas
> 
> would that not be too accurate?
> 

It's mostly accurate, except it doesn't consider:

1. One day (such as March 11 2018 in the US) has 23 hours.

2. Another day (such as November 5 2017 in the US) has 25 hours.

3. If the result is less than, 0 you need to start counting the days 
until NEXT Christmas.

My website code handles all those problems. You might notice the count 
in my sig (which is generated by PHP code) is rounded (up if not whole, 
to avoid the problem of getting to 0 when it's not Christmas yet).

-- 
62 days until the winter celebration (Monday December 25, 2017 12:00:00
AM for 1 day).

Mark Lloyd
http://notstupid.us/

"Enter any 11-digit prime number to continue."

[toc] | [prev] | [next] | [standalone]


#17591

FromLuuk <luuk@invalid.lan>
Date2017-10-26 11:51 +0200
Message-ID<59f1b002$0$818$e4fe514c@news.xs4all.nl>
In reply to#17587
On 25-10-17 00:01, Mark Lloyd wrote:
> On 10/24/2017 03:12 AM, Luuk wrote:
>> On 22-10-17 22:31, hah wrote:
>>> On 10/22/2017 06:58 AM, bill wrote:
>>>> its quiet here - test
>>>
>>> <?php
>>>
>>> print "on-topic test: ";
>>> print ( mktime(0,0,0,12,25) - time() ) / 86400;
>>> print ' days until Christmas';
>>>
>>> ?>
>>
>> on-topic test: 61.617662037037 days until Christmas
>>
>> would that not be too accurate?
>>
> 
> It's mostly accurate, except it doesn't consider:
> 
> 1. One day (such as March 11 2018 in the US) has 23 hours.
> 
> 2. Another day (such as November 5 2017 in the US) has 25 hours.
> 
> 3. If the result is less than, 0 you need to start counting the days 
> until NEXT Christmas.
> 
> My website code handles all those problems. You might notice the count 
> in my sig (which is generated by PHP code) is rounded (up if not whole, 
> to avoid the problem of getting to 0 when it's not Christmas yet).
> 
> -- 
> 62 days until the winter celebration (Monday December 25, 2017 12:00:00
> AM for 1 day).

LOLm where do you in this '62 days' consider those 25 hours?

> 
> Mark Lloyd 

[toc] | [prev] | [next] | [standalone]


#17593

FromMark Lloyd <not@mail.invalid>
Date2017-10-26 12:02 -0500
Message-ID<7zoIB.22653$463.8426@fx13.iad>
In reply to#17591
On 10/26/2017 04:51 AM, Luuk wrote:

[snip]

> LOLm where do you in this '62 days' consider those 25 hours?

Once I have the 2 times in seconds (now and later), I determine is DST 
(Damn Stupid Time, it really makes time calculations more complicated 
for no actual benefit) is active for each of them. This is done using 
the PHP date function; date('I', $time).

If DST is active later but not now, add the DST offset to the interval.

If DST is active now but not later, subtract the DST offset from the 
interval.

"DST offset" is usually 3600 (60*60 for "add 1 hour"), unless you live 
on Lord Howe Island (1800) or Troll Station, Antarctica (7200);

The interval is now ready to be converted to days by dividing by 86400.

-- 
60 days until the winter celebration (Monday December 25, 2017 12:00:00
AM for 1 day).

Mark Lloyd
http://notstupid.us/

"He who hears this name [God] from a Jew must inform the authorities, or
else throw sow dung at him when he sees him and chase him away." [Martin
Luther,"On the Jews and Their Lies",1543]

[toc] | [prev] | [next] | [standalone]


#17594 — Days until Christmas (was: its quiet here - test)

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2017-10-26 19:29 +0200
SubjectDays until Christmas (was: its quiet here - test)
Message-ID<ost629$o1b$1@solani.org>
In reply to#17593
On 26.10.2017 at 19:02, Mark Lloyd wrote:

> On 10/26/2017 04:51 AM, Luuk wrote:
> 
> [snip]
> 
>> LOLm where do you in this '62 days' consider those 25 hours?
> 
> Once I have the 2 times in seconds (now and later), I determine is DST
> (Damn Stupid Time, it really makes time calculations more complicated
> for no actual benefit) is active for each of them. This is done using
> the PHP date function; date('I', $time).
> 
> If DST is active later but not now, add the DST offset to the interval.
> 
> If DST is active now but not later, subtract the DST offset from the
> interval.
> 
> "DST offset" is usually 3600 (60*60 for "add 1 hour"), unless you live
> on Lord Howe Island (1800) or Troll Station, Antarctica (7200);
> 
> The interval is now ready to be converted to days by dividing by 86400.

That appears to be overly complicated.  Wouldn't

  (new DateTime('now'))
    ->diff(new DateTime('2017-12-25T00:00'))
    ->format('%a days until Christmas')

suffice?  Okay, that rounds down, and your solution rounds up, but that
could be catered to.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#17595 — Re: Days until Christmas

FromMark Lloyd <not@mail.invalid>
Date2017-10-26 17:56 -0500
SubjectRe: Days until Christmas
Message-ID<6KtIB.155563$J83.116459@fx06.iad>
In reply to#17594
On 10/26/2017 12:29 PM, Christoph M. Becker wrote:
> Wouldn't
> 
>    (new DateTime('now'))
>      ->diff(new DateTime('2017-12-25T00:00'))
>      ->format('%a days until Christmas')
> 
> suffice?  Okay, that rounds down, and your solution rounds up, but that
> could be catered to.
> 

I've tried this and it seems to be working OK. I may be able to use it 
except I prefer a result that is more precise than days.

One odd thing is that when I looked at the PHP documentation for 
DateTime -> format, it says it uses the same parameters as the "date" 
function, these DO NOT use % signs. 'a' itself shows am or pm. Where did 
you get %a for DateTime -> format?

-- 
60 days until the winter celebration (Monday December 25, 2017 12:00:00
AM for 1 day).

Mark Lloyd
http://notstupid.us/

"He who hears this name [God] from a Jew must inform the authorities, or
else throw sow dung at him when he sees him and chase him away." [Martin
Luther,"On the Jews and Their Lies",1543]

[toc] | [prev] | [next] | [standalone]


#17598 — Re: Days until Christmas

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2017-10-27 01:38 +0200
SubjectRe: Days until Christmas
Message-ID<ostrlr$6i5$1@solani.org>
In reply to#17595
On 27.10.2017 at 00:56, Mark Lloyd wrote:

> On 10/26/2017 12:29 PM, Christoph M. Becker wrote:
>
>> Wouldn't
>>
>>    (new DateTime('now'))
>>      ->diff(new DateTime('2017-12-25T00:00'))
>>      ->format('%a days until Christmas')
>>
>> suffice?  Okay, that rounds down, and your solution rounds up, but that
>> could be catered to.
> 
> I've tried this and it seems to be working OK. I may be able to use it
> except I prefer a result that is more precise than days.
> 
> One odd thing is that when I looked at the PHP documentation for
> DateTime -> format, it says it uses the same parameters as the "date"
> function, these DO NOT use % signs. 'a' itself shows am or pm. Where did
> you get %a for DateTime -> format?

DateTime::diff(DateTime) returns a DateInterval (not a DateTime) object,
and its ::format() method expects a somewhat different format[1].  If
you want more detailed information, you can use something like this:

 ->format('%a days, %h hours, %i minutes and %s seconds …')

[1] <http://www.php.net/manual/en/dateinterval.format.php>

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#17599 — Re: Days until Christmas

FromMark Lloyd <not@mail.invalid>
Date2017-10-26 20:48 -0500
SubjectRe: Days until Christmas
Message-ID<GfwIB.68100$Z%2.54751@fx43.iad>
In reply to#17598
On 10/26/2017 06:38 PM, Christoph M. Becker wrote:

[snip]

> DateTime::diff(DateTime) returns a DateInterval (not a DateTime) object,
> and its ::format() method expects a somewhat different format[1].  If
> you want more detailed information, you can use something like this:
> 
>   ->format('%a days, %h hours, %i minutes and %s seconds …')
> 
> [1] <http://www.php.net/manual/en/dateinterval.format.php>
> 

I found that page, and it looks like it is an acceptable substitute for 
what I use. The difference between the DateTime and DateInterval objects 
was what led to the confusion.

It does handle the DST transition problem correctly.

I don't expect to change to code on my site, since it uses time/date 
extensively and would require a lot of work before it becomes as good as 
it is now using the easier-to-use functions like 
time,date,gmdate,mktime, and gmmktime.

-- 
60 days until the winter celebration (Monday December 25, 2017 12:00:00
AM for 1 day).

Mark Lloyd
http://notstupid.us/

"He who hears this name [God] from a Jew must inform the authorities, or
else throw sow dung at him when he sees him and chase him away." [Martin
Luther,"On the Jews and Their Lies",1543]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web