Git Product home page Git Product logo

ranger's People

Contributors

1ed avatar ahebrank avatar flack avatar javiereguiluz avatar magicoli avatar wivaku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ranger's Issues

Unix timestamp not detected and throw an error

When passing a unix timestamp, the formatter tries to format it as a string and throw an error:

Uncaught Exception: Failed to parse time string (1671062400) at position 8 (0): Unexpected character in (...)vendor/openpsa/ranger/src/Ranger.php:243

The issue is that prepare_date() first checks if the input is a string (although, technically, an integer is also a string).

I solved it by replacing

        if (is_string($input)) {
            return new Datetime($input);
        }
        if (is_int($input)) {
            $date = new Datetime;
            $date->setTimestamp($input);
            return $date;
        }

with

        if (is_numeric($input)) {
            $date = new Datetime;
            $date->setTimestamp($input);
            return $date;
        }
        if (is_string($input)) {
            return new Datetime($input);
        }

I also replaced is_int() by is_numeric(), which is the recommended way to distinguish a number from a string, is_int() failing in some cases.

Support for all day events

Would it be possible to support dates where the times are set to 00:00 to 23:59 - this seems to be a popular setting to display an all day event.

It would be nice to have the option to pass in a string to read "all day"

Add support for level of specificity in date range

This is a great project! It fills almost perfectly a need that I have. However, in my use-case, I would like to be more generic about the date range, by dropping the day field. For example, I currently get back from ranger->format() the text Jan 8 – Oct 26, 2020, but it would be nice to just say Jan – Oct 2020. (Or for the example dates Oct 13–26, 2020, simply saying Oct 2020.)

I could see potential use cases for dropping even the month:

  • For my dates above, outputting just 2020
  • An employment history (2015–2020)
  • A sports season (2019–2020)
  • A person's birth and death dates on a tombstone (1951–2013)

Is this theoretically possible in Ranger right now? Monkeying around with its internals, I seemed to find problems with creating an IntlDateFormatter using only parts of the date.

dates with timezones specified as offsets cause IntlDateFormatter construct exception

This is an edge case, but if your environment uses UTC offsets rather than named timezones:

$time = new \DateTime('2019-01-01')
$time->setTimezone(new \DateTimeZone('-0400'));

and then pass this into Ranger, you'll get this error:

IntlException: datefmt_create: no such time zone: '-0400': U_ILLEGAL_ARGUMENT_ERROR

Luckily there's an easy fix: initialize IntlDateFormatter with the DateTimeZone object, rather than the name (see "timezone" parameter on http://php.net/manual/en/intldateformatter.create.php)

PR incoming.

Minor formatting issue when using the "es" locale

Hi! Thanks a lot for publishing this handy library! I was formatting some date range in my PHP 7.4 app like this:

return (new Ranger($this->getLocale()))
    ->setDateType(\IntlDateFormatter::LONG)
    ->format($this->startsAt, $this->endsAt);

It works perfectly for most languages that I tried:

(en) December 3 – 4, 2020
(fr) 3 – 4 décembre 2020
(de) 3. – 4. Dezember 2020

But in Spanish (locale es) I get this (it even includes an extra white space at the end):

3 de – 4 de diciembre 

It should be:

3 – 4 de diciembre de 2020

(also common -> 3 – 4 de diciembre, 2020)

Maybe I did something wrong, but I wanted to report this issue just in case. Thanks!

'<<<>>>' appearing in range with zh_TW locale

I've modified my test program slightly:

<?php
use OpenPsa\Ranger\Ranger;

require_once 'lib/autoload.inc';

error_reporting(-1);
ini_set('display_errors', '1');

foreach (['en_GB', 'zh_TW'] as $locale) {
    $ranger = new Ranger($locale);
    $ranger
        ->setDateType(IntlDateFormatter::MEDIUM)
        ->setTimeType(IntlDateFormatter::SHORT);
    echo $ranger->format(1711738800, 1711828800);
    echo "<br>\n";
}

and now get the following output:

29 Mar 2024, 19:00 – 30 Mar 2024, 20:00
2024年3月29日, 晚上<<<>>>7:00 – 2024年3月30日, 晚上<<<>>>8:00

The problem only seems to happen if the start and end dates are on different days.

Time weirdly merged when both dates are identically

If I provide the same date with the same time, the time output is weirdly merged.

$ranger = new OpenPsa\Ranger\Ranger('de');
$ranger->setTimeType(IntlDateFormatter::SHORT);
$ranger->format('2022-05-04 20:00:00', '2022-05-04 20:00:00');

The output is 04.05.2022, 20:00 – 00.

I would except the output to be 04.05.2022, 20:00.

Undefined array key warning with zh_TW locale

If I run the following test code:

<?php
use OpenPsa\Ranger\Ranger;

require_once 'lib/autoload.inc';

error_reporting(-1);
ini_set('display_errors', '1');

foreach (['en_GB', 'zh_TW'] as $locale) {
    $ranger = new Ranger($locale);
    $ranger
        ->setDateType(IntlDateFormatter::MEDIUM)
        ->setTimeType(IntlDateFormatter::SHORT);
    echo $ranger->format(1711738800, 1711738800);
    echo "<br>\n";
}

I get the output

29 Mar 2024, 19:00
Warning: Undefined array key 8 in C:\inetpub\wwwroot\mrbs-main\lib\OpenPsa\Ranger\Ranger.php on line 195 Warning: Trying to access array offset on null in C:\inetpub\wwwroot\mrbs-main\lib\OpenPsa\Ranger\Ranger.php on line 195 2024年3月日, B日, B::

I am running the latest version of Ranger downloaded from the Master branch today using PHP 8.3.3 on Windows.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.