Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121498 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24815 invoked from network); 28 Oct 2023 17:53:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Oct 2023 17:53:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9FE4F1804BC for ; Sat, 28 Oct 2023 10:53:55 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 10:53:55 -0700 (PDT) Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-32daeed7771so1948047f8f.3 for ; Sat, 28 Oct 2023 10:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698515633; x=1699120433; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ceguhmgPkBD55r3neaPg86InXUj54/Hodien5wL09II=; b=iIVodLiamq0Wy3uzR97kc3Lb1oetmLkKRNL8iQYQ2XRkZTW6ndRxZ5z0hAnunfBTvn uRQ38+4GoViRobIzHElswzuaLIIPEHDv/CEIHv9Ez/Uq3cxcLriUkQ6tzemxubU/i+gl xM1KIIRwB68fJVVRaMFgZRaQ2ey6xDtLDTx9J8Y1bt7YjV4HkjiI9kq6zU9H7oDCIjkD VoPKVfQTU8A5AQG53+YAAozchtgR77zlc+IIGB7qpAiW02UZJq7OBdKH2WCDHroLhn23 d5rb/qp273b3idjUunSA5Rlk5J10/4Boyfww3k68use1PNkPy3Aq7TBjdcZ67yuIAm1Q XzWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698515633; x=1699120433; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ceguhmgPkBD55r3neaPg86InXUj54/Hodien5wL09II=; b=h5SLYbLQOdN/F33RSbMGexRzX62/UaN7ApcmykeHSpBWv4ZKmftyrjR9LxwCoPTtsL YSTiv76iniGM6ipx4cOkqYLu+6CcWj41HwykNnaiA+0F4etANccKC4+848AH+yeZjZCs f8LFsB2X6i7BdhGO+2GMcpv6/JFkfrKuYCa28OCoaovfqrRMcKsImO8x06dnZzfKT78U O9LL3jIZIATBvKPLZodh/wx9+bWhT3i0c2mSVfRYyMJUjiRC7gCeePv5wUYO2JmUo2zz j/0KPzSP5FzLe8cF2UL0nIZ8dK07FnTXI9v5LSXsLV+JOD6+XMDMv64WqmYQcBkOAs+p k0QQ== X-Gm-Message-State: AOJu0Yz3EZlNh+y7mKBJAUZjgetyiBlcdEzgoIFcbRIlLDO0gl/fa4Ld YjKtil84Kj6xPDmfjA6CLE3cVIDQXac= X-Google-Smtp-Source: AGHT+IGFfcvqn43MrTW7Ajp6E2dgK77ePo+H5VccIBxJ8D/qKP9H8uEdjxsoYdcBepBaqxF9tbKHNw== X-Received: by 2002:a5d:6dad:0:b0:32f:762f:7f9f with SMTP id u13-20020a5d6dad000000b0032f762f7f9fmr3013137wrs.16.1698515633281; Sat, 28 Oct 2023 10:53:53 -0700 (PDT) Received: from [192.168.0.22] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.googlemail.com with ESMTPSA id q6-20020a056000136600b0032f7f4d008dsm992394wrz.20.2023.10.28.10.53.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 28 Oct 2023 10:53:52 -0700 (PDT) Message-ID: <94525acc-9eb5-44f3-9c55-8f076eb29693@gmail.com> Date: Sat, 28 Oct 2023 18:53:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Saki Takamachi Cc: internals@lists.php.net References: <6A744D0D-8841-45BE-A72A-A1323AED52BE@sakiot.com> Content-Language: en-GB In-Reply-To: <6A744D0D-8841-45BE-A72A-A1323AED52BE@sakiot.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] New DateTime[Immutable]::createFromTimestamp From: rowan.collins@gmail.com (Rowan Tommins) On 28/10/2023 16:47, Saki Takamachi wrote: > Yes, I'm assuming a timestamp that includes up to microseconds. This > is because in the last example of the PR description, the microsecond > timestamp was expressed as a float. Floating point numbers don't suddenly become unpredictable after a certain point, nor is there a strict relationship with any number of decimal digits. Rather, their absolute precision varies based on their magnitude - for each power of 2 in magnitude, they lose a power of 2 in absolute precision. More specifically, an IEEE float64 / double precision has 53 significant bits, which can be allocated to either the whole or fractional part of a number. It has a precision of at least 1 up to 2**53-1, at least 0.5 up to 2**52-1, and so on - a precision of 1/2**(53-n) for values up to (2**n)-1 Plugging that formula into a spreadsheet, I get: * accuracy to nearest microsecond up to the year 2242 (1/2**20 up to 2**33-1 seconds) * accuracy to nearest 10 microseconds up to the year 4147 (1/2**17 up to 2**36-1 seconds) * accuracy to nearest millisecond up to the year 280701 (1/2**10 up to 2**43-1 seconds) An application that needs to represent a timestamp more than 200 years in the future, with a precision of 1 microsecond, is going to be very rare. > 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 Distinguishing between the two is up to the user, just as it is up to the user to feed the right format to createFromFormat(). If they know they have a number of microseconds, they could use DateTimeImmutable::createFromTimestamp($value / 1_000_000) - as discussed above, this will not lose any accuracy for dates in the next 200 years or so. Regards, -- Rowan Tommins [IMSoP]