alphp / strftime

This provides a cross-platform alternative to strftime() for when it will be removed from PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

doesn't work with LC_TIME=nb_NO.UTF8 ?

divinity76 opened this issue · comments

my LC_TIME is "nb_NO.UTF8", and $format is "%A %d. %B" and $timestamp is 1655935200 and strftime() gives me "torsdag 23. juni", but \PHP81_BC\strftime gives me "Thursday 23. June"

.. any idea what went wrong here? reproduce script:

<?php
require_once('vendor/autoload.php');
if(false === setlocale(LC_TIME, "nb_NO.UTF8")){
 die("error: locale nb_NO.UTF8 is not installed");
}
$stamp = 1655935200;
$format = "%A %d. %B";
var_dump(\PHP81_BC\strftime($format, $stamp));
var_dump(strftime($format, $stamp));

outputs on my system (PHP7.4.29):

root@75cee9b6f638:/var/www# php test.php
string(17) "Thursday 23. June"
string(16) "torsdag 23. juni"

what went wrong here?

Wow. for some reason the command composer require php81_bc/strftime installs version 0.0.2 by default. after i explicitly said
composer require php81_bc/strftime ^0.5.0 , it installed version 0.5.0, where this issue is fixed.

any idea why composer defaults to version 0.0.2 when 0.5.0 is available? (and has been available for 3 months now)

Composer cache may have affected you:

>composer require php81_bc/strftime
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^0.5.0 for php81_bc/strftime
./composer.json has been created
Running composer update php81_bc/strftime
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking php81_bc/strftime (0.5.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing php81_bc/strftime (0.5.0): Extracting archive
Generating autoload files
>composer info php81_bc/strftime
name     : php81_bc/strftime
descrip. : Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible)
keywords :
versions : * 0.5.0
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage :
source   : [git] https://github.com/alphp/strftime.git 4c1b56eaae4bb3f02f994ba47c2e5a225378e62f
dist     : [zip] https://api.github.com/repos/alphp/strftime/zipball/4c1b56eaae4bb3f02f994ba47c2e5a225378e62f 4c1b56eaae4bb3f02f994ba47c2e5a225378e62f
path     : E:\_\kk\vendor\php81_bc\strftime
names    : php81_bc/strftime

support
issues : https://github.com/alphp/strftime/issues
source : https://github.com/alphp/strftime

autoload
files

requires
ext-intl *
php >=7.1.0

requires (dev)
phpunit/phpunit @stable

@alphp no i don't think so, here is a system that i believe has never ran composer before, and it also defaulted to 0.0.2:

hans@DESKTOP-2LHJILI:~/test$ ls
hans@DESKTOP-2LHJILI:~/test$ composer
-bash: composer: command not found
hans@DESKTOP-2LHJILI:~/test$ php -v
PHP 7.3.7 (cli) (built: Jul 21 2020 18:15:38) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies
hans@DESKTOP-2LHJILI:~/test$ date -u --iso-8601=s
2022-06-16T14:10:04+00:00
hans@DESKTOP-2LHJILI:~/test$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Installer verified
Downloading...

Composer (version 2.3.7) successfully installed to: /home/hans/test/composer.phar
Use it: php composer.phar

Some settings on your machine may cause stability issues with Composer.
If you encounter issues, try to change the following:

The zlib extension is not loaded, this can slow down Composer a lot.
If possible, install it or recompile php with --with-zlib

The php.ini used by your command-line PHP is: /etc/php.ini
If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.

hans@DESKTOP-2LHJILI:~/test$ ./composer.phar --version
Composer version 2.3.7 2022-06-06 16:43:28
hans@DESKTOP-2LHJILI:~/test$ ./composer.phar require php81_bc/strftime
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^0.0.2 for php81_bc/strftime
./composer.json has been created
Running composer update php81_bc/strftime
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking php81_bc/strftime (0.0.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading php81_bc/strftime (0.0.2)
  - Installing php81_bc/strftime (0.0.2): Extracting archive
Generating autoload files
hans@DESKTOP-2LHJILI:~/test$ ./composer.phar info php81_bc/strftime
name     : php81_bc/strftime
descrip. : Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible)
keywords :
versions : * 0.0.2
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage :
source   : [git] https://github.com/alphp/strftime.git a6b25e3e2ee931faf3d80bb5c0fba3552300d02a
dist     : [zip] https://api.github.com/repos/alphp/strftime/zipball/a6b25e3e2ee931faf3d80bb5c0fba3552300d02a a6b25e3e2ee931faf3d80bb5c0fba3552300d02a
path     : /home/hans/test/vendor/php81_bc/strftime
names    : php81_bc/strftime

support
issues : https://github.com/alphp/strftime/issues
source : https://github.com/alphp/strftime

autoload
files

requires
php >=5.6.0

It's strange. I don't know how the composer/packagist network works, but it seems that at some point the cache is not up to date.
I have tried clearing the local cache composer clear-cache and doing require php81_bc/strftime composer has installed the correct version.

strange indeed. do you have Docker?

I don't work with docker.
I have tried on Windows and CentOS6 without problems: composer install the latest version (0.5).

@alphp the plot thickens. I am able to reproduce it on a clean docker image using the newest Composer version, this Dockerfile reproduce the issue, installing 0.0.2 on a clean system that has never ran Composer before:

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive 
RUN apt-get update -y \
    && apt-get install -y php-cli wget git
RUN wget 'https://getcomposer.org/installer' -O 'composer-setup.php'
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN ./composer.phar require php81_bc/strftime

However, if we use an older composer, the composer version that ships with Ubuntu 20.04, currently composer version 1.10.1-1, it does not reproduce the issue, this Dockerfile installs 0.5.0:

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive 
RUN apt-get update -y \
    && apt-get install -y php-cli composer git
RUN composer require php81_bc/strftime

(it uses Ubuntu 20.04's default Composer, the ancient v1.10.1)

practically speaking, it reproduce on Composer version 2.3.7 (installing 0.0.2) but it does not reproduce on Composer version 1.10.1 (it installs 0.5.0), when you said it works on Windows and CentOS, which versions of Composer were they running?

2.0.1 in CentOS 6, 2.3.5 and 2.3.7 in Windows.
Can you test to run composer require php81_bc/strftime:@stable?

"composer require php81_bc/strftime:@stable" also installs 0.0.2

btw if you could install Docker on a linux system, the way to test it on Docker for Linux is:

mkdir -p testdir;
cd testdir;
echo -ne 'FROM ubuntu:20.04\nENV DEBIAN_FRONTEND'\
'=noninteractive \nRUN apt-get update -y \\\n   '\
' && apt-get install -y php-cli wget git\nRUN wg'\
'et '\''https://getcomposer.org/installer'\'' -O'\
' '\''composer-setup.php'\''\nRUN php composer-s'\
'etup.php\nRUN php -r "unlink('\''composer-setup'\
'.php'\'');"\nRUN ./composer.phar require php81_'\
'bc/strftime' > Dockerfile;
sudo docker build .;

(btw i didn't type that echo command manually, i generated it with https://3v4l.org/59Fdt )
and the output should be something like

hans@devad22:/test2$ cat Dockerfile
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive 
RUN apt-get update -y \
    && apt-get install -y php-cli wget git
RUN wget 'https://getcomposer.org/installer' -O 'composer-setup.php'
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN ./composer.phar require php81_bc/strftime:@stable


hans@devad22:/test2$ sudo docker build .
Sending build context to Docker daemon  2.048kB
Step 1/7 : FROM ubuntu:20.04
 ---> 20fffa419e3a
Step 2/7 : ENV DEBIAN_FRONTEND=noninteractive
 ---> Using cache
 ---> 8ab983f5c55b
Step 3/7 : RUN apt-get update -y     && apt-get install -y php-cli wget git
 ---> Using cache
 ---> 82d179789932
Step 4/7 : RUN wget 'https://getcomposer.org/installer' -O 'composer-setup.php'
 ---> Using cache
 ---> a858500fa1d1
Step 5/7 : RUN php composer-setup.php
 ---> Using cache
 ---> 9ea972d3d75e
Step 6/7 : RUN php -r "unlink('composer-setup.php');"
 ---> Using cache
 ---> c482a3f8df61
Step 7/7 : RUN ./composer.phar require php81_bc/strftime:@stable
 ---> Running in fb1d1d9cb859
./composer.json has been created
Running composer update php81_bc/strftime
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking php81_bc/strftime (0.0.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
    Failed to download php81_bc/strftime from dist: The zip extension and unzip/7z commands are both missing, skipping.
Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
    Now trying to download from source
  - Syncing php81_bc/strftime (0.0.2) into cache
  - Installing php81_bc/strftime (0.0.2): Cloning a6b25e3e2e from cache
Generating autoload files
Removing intermediate container fb1d1d9cb859
 ---> 7a29d3e572e1
Successfully built 7a29d3e572e1

(could be a nice introduction to Docker, there's a first time for everything right? ^^)

in any case, looks like a Composer issue, not a alphp/strftime issue, i've raised an issue with Composer: composer/composer#10884

I will leave the issue open for a while to follow up.

composer/composer#10884 (comment)

Solution on your end would be to ensure intl is enabled.

composer/composer#10896
image