Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121496 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18234 invoked from network); 28 Oct 2023 16:09:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Oct 2023 16:09:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 80974180504 for ; Sat, 28 Oct 2023 09:09:34 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS34011 80.237.132.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wp160.webpack.hosteurope.de (wp160.webpack.hosteurope.de [80.237.132.167]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 28 Oct 2023 09:09:33 -0700 (PDT) Received: from [2a02:8109:b323:1700:e5f9:7932:39d4:19d7]; authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1qwlsS-0004K1-CR; Sat, 28 Oct 2023 18:09:32 +0200 Content-Type: multipart/alternative; boundary="------------02nWlk06kkjtIOuTP4Jjv1yB" Message-ID: Date: Sat, 28 Oct 2023 18:09:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: internals@lists.php.net References: <675b54f5-3fe5-4ecd-89dc-4c9dfc0cd77e@mabe.berlin> In-Reply-To: X-bounce-key: webpack.hosteurope.de;marc@mabe.berlin;1698509374;3a88ffdc; X-HE-SMSGID: 1qwlsS-0004K1-CR Subject: Re: [PHP-DEV] New DateTime[Immutable]::createFromTimestamp From: marc@mabe.berlin (Marc) --------------02nWlk06kkjtIOuTP4Jjv1yB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 28.10.23 17:33, Rowan Tommins wrote: > On 28 October 2023 15:40:29 BST, Saki Takamachi wrote: >> Hi Marc, >> >> Personally, I don't think these are necessarily necessary since there is a "from format". > As noted on the PR, both the default constructor and createFromFormat require the input to be converted to a string, which tends to make code messy. It's then converted back to an integer internally, which isn't very efficient. > > I would be in favour of adding this method. Thanks for your support :) @saki, If you are dealing with unix timestamps you do (or should) handle these as numbers and being forced to to stringify these numbers only to parse it as numbers is error prone and not performant at all. >> I have one concern. float is imprecise, so I don't think it's suitable for this kind of use. For timestamps, 16 digits are used, which exceeds the guaranteed precision of 15 digits on non-IBM platforms. > I'm not sure where you got those numbers; on a 64-bit architecture (surely the vast majority of PHP installs), a float can precisely represent any whole number from -2**53 up to 2**53 - 1. As a Unix timestamp, that's a one-second accuracy for any time 285 million years into the past or future.https://www.wolframalpha.com/input?i=2**53+as+unix+timestamp > > Possibly you're thinking of a representation that counts integers as milliseconds or microseconds, instead of seconds? On a 64bit system it's obvious to have higher precision if you handle the integer and fractions part separately (as timelib does) but this doesn't help if you already have a floating point number at hand. Also JS uses a double float for timestamps in milliseconds which is the most used lang together with PHP and there is tons of code out there who does a simple */ 1000 to pass a date-time to/from JS, which I wouldn't necessary decline. One think that could be done is adding an optional second argument for allowing the microseconds part but again forcing PHP users to extract seconds and microseconds from a float isn't user friendly so I would still allow a float in the first place which than opens the question what to do if both arguments have fractions. Additionally this would break Carbons `createFromTimestamp($timestamp, $tz = null)`. Instead it would probably be better to add a `[get|set]Microseconds` method as well instead. I'm open for adding another PR for this. PS: I didn't add a timezone argument here because a unix timestamp is in UTC by definition and changing the TZ is just one `setTimezone` call away not having to deal with any default/system/ini TZ setting. > Regards, Best, Marc --------------02nWlk06kkjtIOuTP4Jjv1yB--