Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

its quiet here - test

13 views
Skip to first unread message

bill

unread,
Oct 22, 2017, 7:59:03 AM10/22/17
to
its quiet here - test

hah

unread,
Oct 22, 2017, 4:31:19 PM10/22/17
to
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';

?>

Luuk

unread,
Oct 24, 2017, 4:12:35 AM10/24/17
to
on-topic test: 61.617662037037 days until Christmas

would that not be too accurate?

Mark Lloyd

unread,
Oct 24, 2017, 6:01:58 PM10/24/17
to
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."

Luuk

unread,
Oct 25, 2017, 2:59:48 AM10/25/17
to
what?

On 25-10-17 00:01, Mark Lloyd wrote:

Mark Lloyd

unread,
Oct 25, 2017, 12:17:33 PM10/25/17
to
On 10/25/2017 01:59 AM, Luuk wrote:
> what?
>
> On 25-10-17 00:01, Mark Lloyd wrote:

It was in September when I first wrote the "dtc" (days until Christmas)
algorithm. It was expected to change the number of days at midnight, but
it was actually changing at 1AM. The reason being the 25-hour day in
November (National mess-with-your-clock day, where the hour 1:00:00 to
1:59:59 AM occurs twice).

Assuming a day always has 24 hours (24 * 60 * 60 = 86400 seconds) is one
of the common mistakes people make when working with dates.

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

Mark Lloyd
http://notstupid.us/

"Heresy is only another word for freedom of thought." [Graham Greene,
1981]

R.Wieser

unread,
Oct 25, 2017, 12:51:55 PM10/25/17
to
Mark,

> The reason being the 25-hour day in November (National mess-
> with-your-clock day, where the hour 1:00:00 to 1:59:59 AM occurs twice).

Isn't that day offsetted by another day somewhere in the spring, which is
only 23 hours long ? Did you account for that one too ? :-)

> Assuming a day always has 24 hours (24 * 60 * 60 = 86400 seconds) is one
> of the common mistakes people make when working with dates.

The *most* common one is to try to write them yourself, instead of using the
ones that are already available.

Just take the two date/times, have the OS convert them from local to UTC
(with respect to its summer/winter time), and you get an *exact* answer
back, even accounting for the leap second that happens about once every four
years. :-)

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

As long as you output in days, who cares about that one hour of that 25-hour
day (and that other one of that 23-hour day) ?

Regards,
Rudy Wieser






"Mark Lloyd" <n...@mail.invalid> wrote in message
news:sO2IB.20191$fc3...@fx35.iad...

Luuk

unread,
Oct 26, 2017, 5:51:15 AM10/26/17
to
On 25-10-17 00:01, Mark Lloyd wrote:
LOLm where do you in this '62 days' consider those 25 hours?

>
> Mark Lloyd


Mark Lloyd

unread,
Oct 26, 2017, 12:47:59 PM10/26/17
to
On 10/25/2017 11:51 AM, R.Wieser wrote:
> Mark,
>
>> The reason being the 25-hour day in November (National mess-
>> with-your-clock day, where the hour 1:00:00 to 1:59:59 AM occurs twice).
>
> Isn't that day offsetted by another day somewhere in the spring, which is
> only 23 hours long ? Did you account for that one too ? :-)

It is in the case of finding the days until Christmas, when it's still
February (when you have BOTH the 23-hour day and the 25-hour day during
that interval). It does NOT offset it when your interval crosses only
ONE of those days (in my case, only one [the 25-hour day] comes between
September and December).


>> Assuming a day always has 24 hours (24 * 60 * 60 = 86400 seconds) is one
>> of the common mistakes people make when working with dates.
>
> The *most* common one is to try to write them yourself, instead of using the
> ones that are already available. > Just take the two date/times, have the OS convert them from local to UTC

That is irrelevant here, since both the times I'm concerned about
here(now and Christmas) are local times in the SAME timezone.

> (with respect to its summer/winter time), and you get an *exact* answer
> back, even accounting for the leap second that happens about once every four
> years. :-)

In this case, I had a correct interval in SECONDS, and needed to convert
it to days. Perhaps you could explain how you did THAT.
--
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]

Mark Lloyd

unread,
Oct 26, 2017, 1:03:04 PM10/26/17
to
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).

Christoph M. Becker

unread,
Oct 26, 2017, 1:29:50 PM10/26/17
to
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

Mark Lloyd

unread,
Oct 26, 2017, 6:56:07 PM10/26/17
to
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?

R.Wieser

unread,
Oct 26, 2017, 7:04:29 PM10/26/17
to
Mark,

> It is in the case of finding the days until Christmas, when it's still
> February (when you have BOTH the 23-hour day and the 25-
> hour day during that interval).

.... Or any day after chrismas but before the first summer-time day (a
two-and-a-half month stretch.)

Regards,
Rudy Wieser


Mark Lloyd

unread,
Oct 26, 2017, 7:24:00 PM10/26/17
to
Yes. I was using February as an example.
More generally, an EQUAL number of DST beginnings and DST endings
between now and the event you're counting down to.

> Regards,
> Rudy Wieser

Christoph M. Becker

unread,
Oct 26, 2017, 7:38:42 PM10/26/17
to
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

Mark Lloyd

unread,
Oct 26, 2017, 9:48:27 PM10/26/17
to
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.

R.Wieser

unread,
Oct 27, 2017, 3:26:02 AM10/27/17
to
Mark,

> Yes. I was using February as an example.

Than its good to hear you where not forgetting about that other, as
important day than the one with 25 hours you shone your spotlight on.

Regards,
Rudy Wieser


Mark Lloyd

unread,
Oct 27, 2017, 1:31:52 PM10/27/17
to
I had not mentioned the 23-hour day because it does not occur during the
interval between NOW and Christmas.

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

Mark Lloyd
http://notstupid.us/

"My mind is my own church." -- Thomas Paine
0 new messages