jasonlewis / expressive-date Goto Github PK
View Code? Open in Web Editor NEWA fluent extension to PHPs DateTime class.
License: BSD 2-Clause "Simplified" License
A fluent extension to PHPs DateTime class.
License: BSD 2-Clause "Simplified" License
Hi,
Major problem with PHP is that we can get long date only in English. I want to be able to get long date also in other languages.
For example, in English:
1 Jan 1970 / 1 January 1970
And in Polish:
1 sty 1970 / 1 stycznia 1970
Of course, I don't expect you to include translations by default. I only want to be able to translate it by myself using your lib.
Currently the getRelativeDate
method only ouputs in english, it would be nice to be able to set a custom $units
array and the ago
string to allow manual translation of the date.
I'm trying to use ExpressiveDate via composer although I cannot figure it out. I've tried...
$date = new \ExpressiveDate\ExpressiveDate();
$date = new \ExpressiveDate();
$date = new ExpressiveDate();
Trying to use minusHours() with anything less than one but greater than 0 throws the following exception.
Exception: DateInterval::__construct(): Unknown or bad format (PT0.5H)
There should be a check inside of modifyHours() that looks for floats between 0 and 1 and redirects them to modifyMinutes instead, since its perfectly reasonable that somebody might be trying to pass a fraction of an hour.
I would like to use your php extension. I would like to translate (getRelativeDate() / $units prefix, postfix etc.). Can you solve this problem? For example if the extension use language file.. then I be able to translate. Thanks for your support.
it would be awesome to have some additional methods:
$date->copy()->startOfWeek()
)Week methods also will require week start day definition:
Also would be great to hint magic methods like getDay(),setMonth() and etc
Have you thought at all about adding support for business days?
So for example, if
$date = new ExpressiveDate; // Let's say this is a Friday
$date->addDays(1); // This would give you Saturday
$date->addBusinessDays(1); // This would give you Monday
Support for holidays would be a little more complicated, because we would probably need to pass in the holidays into object configuration somehow, since it will vary by country / locale.
But maybe, $holidays
were an array of date objects:
$holidays = array(
$monday
);
ExpressiveDave::initializeHolidays($holidays);
$date->addBusinessDays(1); // This would be Tuesday, since Monday is holiday
The default format is:
protected $defaultDateFormat = 'jS F, Y \a\\t g:ia';
https://github.com/jasonlewis/expressive-date/blob/master/src/ExpressiveDate.php#L36
But the README.md says the time looks like:
$date->startOfWeek(); // 26th November, 2012 at 12:00 AM
Shouldn't it be?:
$date->startOfWeek(); // 26th November, 2012 at 12:00am
This tripped me up a bit when I was TDDin of my classes.
It'd be great if you could also integrate something like https://pear.php.net/package/Date_HumanDiff to generate time/dates in a human readable format.
Pardon, $date->getRelativeDate(); does that :)
It would be cool to be able to use relative date to a specific length, then use a more normal date.
Currently I write it something like this (pseudocode):
$date = new ExpressiveDate('January 31, 1991');
$current = new ExpressiveDate();
if($current->lessOrEqualTo($date->clone()->addOneWeek())) {
return $date->getRelativeDate();
} else {
return $date->getShortDate();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.