Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121510 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15400 invoked from network); 29 Oct 2023 18:43:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Oct 2023 18:43:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BE34F1804F5 for ; Sun, 29 Oct 2023 11:43:17 -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.3 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SCC_BODY_URI_ONLY,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 ; Sun, 29 Oct 2023 11:43:17 -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 1qxAkm-00053G-Cj; Sun, 29 Oct 2023 19:43:16 +0100 Message-ID: <77bce668-2f12-4a6e-826c-6b8997e52994@mabe.berlin> Date: Sun, 29 Oct 2023 19:43:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: internals@lists.php.net References: <505DD7E0-A720-4357-A22F-2F7B42EEE9F3@sakiot.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;marc@mabe.berlin;1698604997;c61777a9; X-HE-SMSGID: 1qxAkm-00053G-Cj Subject: Re: [PHP-DEV] New DateTime[Immutable]::createFromTimestamp From: marc@mabe.berlin (Marc) On 29.10.23 19:41, Marc wrote: > Hi Saki, > > On 28.10.23 18:32, Saki Takamachi wrote: >> Hi Marc, >> >>> 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. >> I think there is no problem if it is up to milliseconds. This becomes >> a problem when it includes up to microseconds. >> >> Another problem is that there are "millisecond" and "microsecond" >> timestamp formats that do not include dots, how should they be >> handled? In reality, such a use case is unlikely, but it is virtually >> impossible to tell the difference between the two: >> >> timestamp: 1698510347 >> => second: 2023-10-28 16:25:47(UTC) >> => millisecond: 1970-01-20 15:48:30.347(UTC) >> > I'm not sure I fully understand what you mean. > > Obviously if you have a string to be parsed you need to use the > existing `createFromFormat`. > >>> 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. > > Just opened another PR for adding `[get|set]Microseconds` to support > handling seconds + microseconds as separate integers. Missed the link: https://github.com/php/php-src/pull/12557 > >> Regards. >> >> Saki > > > Best, > Marc >