Download the PHP package bureaux-a-partager/moment without Composer
On this page you can find all versions of the php package bureaux-a-partager/moment. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bureaux-a-partager/moment
More information about bureaux-a-partager/moment
Files in bureaux-a-partager/moment
Package moment
Short Description Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
License MIT
Informations about the package moment
_ _ _ __ ___ ___ _ __ ___ ___ _ __ | |_ _ __ | |__ _ __ | '_ ` _ \ / _ \| '_ ` _ \ / _ \ '_ \| __| | '_ \| '_ \| '_ \ | | | | | | (_) | | | | | | __/ | | | |_ _| |_) | | | | |_) | |_| |_| |_|\___/|_| |_| |_|\___|_| |_|\__(_) .__/|_| |_| .__/ |_| |_|
Change log
Intro
What is moment.php?
Date library for parsing, manipulating and formatting dates w/ i18n.
Any dependencies?
PHP 5.3 or later since moment.php is based on php's DateTime Class.
Install
Easy install via composer. Still no idea what composer is? Inform yourself here.
Quick examples
Get a moment
Accepted date formats
Moment parses the following date formats as input:
Switch locale
Have a look at the folder to see all supported languages. Default locale is .
Supported languages so far:
Arabic (Tunisia)
Catalan
Chinese
Chinese (traditional)
Czech
Danish
Dutch
English (British)
English (American)
French (Europe)
German (Germany)
Hungarian
Indonesian
Italian
Japanese
Lengadocian
Latvian (Latviešu)
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Russian (Basic version)
Spanish (Europe)
Swedish
Ukrainian
Thai
Turkish
Vietnamese
Switch timezones
Change default timezone
Custom format
I. PHP only (Standard)
Formats are based on PHP's Date function and DateTime class.
II. Non-php formats
You can now inject different format handling by passing along a class which implements the . You can find an example within the test folder for implementing all formats from moment.js. Thanks to Ashish for taking the time to match formats to those of PHP. Have a look at the test script to see the example in action.
Everybody can write format classes in the same manner. Its easy and scalable.
Custom formats
can also come as part of every Locale
. If it does not exist for your locale yet go ahead and add it. See an example for the French locale.
III. Easy text escaping
Just wrap all your text within and all characters will be automatically escaped for you.
IV. Fixed ordinal representations
PHP's interal ordinal calculation seems to be buggy. I added a quick fix to handle this issue.
The following example prints the week of the year of the given date. It should print :
Create custom moments and manipulate it
I. Past/Future moments
II. Clone a given moment
Sometimes its useful to take a given moment and work with it without changing the origin. For that use .
Alternately, you can enable immutable mode on the origin.
Immutable mode makes all modification methods call cloning()
implicitly before applying their modifications.
III. Methods for manipulating the date/time
Add | Subtract |
---|---|
addSeconds($s) | subtractSeconds($s) |
addMinutes($i) | subtractMinutes($i) |
addHours($h) | subtractHours($h) |
addDays($d) | subtractDays($d) |
addWeeks($w) | subtractWeeks($w) |
addMonths($m) | subtractMonths($m) |
addYears($y) | subtractYears($y) |
IV. Setter/Getter
Setter | Getter |
---|---|
setSecond($s) | getSecond() |
setMinute($m) | getMinute() |
setHour($h) | getHour() |
setDay($d) | getDay() |
setMonth($m) | getMonth() |
setYear($y) | getYear() |
-- | getQuarter() |
Difference between dates
Get date periods (week, month, quarter)
Sometimes its helpful to get the period boundaries of a given date. For instance in case that today is Wednesday and I need the starting-/end dates from today's week. Allowed periods are , and .
Same procedure for monthly and quarterly periods:
Calendar Times
Calendar time displays time relative to , but slightly differently than . will format a date with different strings depending on how close to today the date is.
Time | Display |
---|---|
Last week | Last Monday at 15:54 |
The day before | Yesterday at 15:54 |
The same day | Today at 15:54 |
The next day | Tomorrow at 15:54 |
The next week | Wednesday at 15:54 |
Everything else | 04/09/2014 |
Note: Use to leave out the time .
startOf / endOf
Same process as for moment.js: mutates the original moment by setting it to the start/end of a unit of time.
Note: I ignored the period of since we are not dealing with milliseconds.
Get dates for given weekdays for upcoming weeks
For one of my customers I needed to get moments by selected weekdays. The task was: give me the dates for and for the next three weeks. So I added a small handler which does exactly this. As result you will receive an array filled with .
You can now run through the result and put it formatted into a drop-down field or for whatever you might need it.
Roadmap
- Try to port useful methods from moment.js
- Add unit tests
Changelog
1.26.10
- fixed:
- Occitan locale
1.26.9
- fixed:
- Russian locale issue
1.26.8
- added:
- Portuguese (pt_PT)
1.26.7
- fixed:
- Hungarian locale weekdays order
1.26.6
- added:
- allow initialising Moment with unix timestamp without leading @
1.26.5
- fixed:
- Fix format of 'LLL' in Custom Formats
1.26.4
- fixed:
- removed php5.4+ only syntax
1.26.3
- fixed:
- Danish day- and monthnames correct case
- French locale
- PHPDocs
- added:
- consts for
NO_TZ_MYSQL
,NO_TZ_NO_SECS
andNO_TIME
when parsing dates
1.26.2
- added:
- Dutch customFormat
1.26.1
- fixed:
- Russian locale
1.26.0
- added:
- Turkish locale
- fixed:
- Lengadocian locale
1.25.1
- fixed:
- PHP7.1 setTime requires
$microseconds
- PHP7.1 setTime requires
1.25
- added:
- Ukrainian locale
1.24
- added:
- Hungarian locale
1.23.1
- fixed:
- Lengadocian locale
1.23.0
- added:
- Vietnamese locale
- Lengadocian locale
1.22.0
- added:
- Change default timezone
- fixed:
- FormatsInterface docs
1.21.0
- added:
- Arabic locale
- Custom format on locale level
1.20.9
- fixed:
- Russian locale
- added:
- Russian locale tests
1.20.8
- fixed:
- Polish locale
- Calculation of seconds
1.20.7
- fixed:
- Russian: more relative time fixes
1.20.6
- fixed:
- Russian locale relative time: day handling
1.20.5
- fixed:
- missing immutable handling
1.20.4
- fixed:
- Improved Polish locale (added Nominativ)
1.20.3
- fixed:
- Chinese locale
1.20.2
- added accepted formats to README
1.20.1
- fixed:
- Thai locale
1.20.0
- added:
- Catalan locale
- fixed:
- Polish locale test
1.19.0
- added:
- Russian locale
- fixed:
- Polish locale test
1.18.0
- added:
- Immutable mode
- fixed:
- Polish locale
1.17.0
- added:
- Polish locale
1.16.0
- added:
- Indonesian locale
1.15.0
- added:
- Japanese locale
1.14.1
- fixed:
- typo in Dutch locale
1.14.0
- added:
- Dutch locale
1.13.0
- added:
- Swedish locale
1.12.0
- added:
- Danish locale
1.11.4
- fixed:
- fixed starting/ending weekday for Romanian locale
1.11.3
- fixed:
- adding delimiter character to Italian locale
1.11.1
- fixed:
- passing back new instance for startOf/endOf for week, month, quarter
1.11.0
- added:
- locale Czech
1.10.4
- added:
- locale receives as \Closure the following params
- locale receives as \Closure the following params
1.10.3
- added:
- fixed passing closures to locale (calendar, relativeTime)
- set correct german locale information
1.10.2
- added:
- fixed Thai locale strings
1.10.1
- added:
- locale traditional Chinese
1.10.0
- added:
- locale Chinese
- ordinal formatter receives now the e.g. the token within is
1.9.1
- fixed: english ordinal issue for numbers between 11 - 13
1.9.0
- added: locale Italian
1.8.1
- fixed: english ordinal issue
1.8.0
- added: locale Portuguese
1.7.2
- fixed:
- Locale displayed wrong month name (#34)
- Changed the order of weekdays within locale files
1.7.1
- added:
- getWeekdayNameLong()
- getWeekdayNameShort()
- getMonthNameLong()
- getMonthNameShort()
1.7.0
- added:
- Locale: Thai
1.6.0
- added:
- Locale
- MomentFromVo:
- getMonths()
- getYears()
- getRelative()
- fixed:
- MomentFromVo:
- getSeconds() shows now direction as well
- MomentFromVo:
1.5.3
- fixed:
- timezone issue which occured only for unixtime dates
- other:
- MomentFromVo:
- direction returns now: "future" (-) / "past" (+)
- time values are now type casted as floats
- MomentFromVo:
1.5.2
- fixed:
- unrecognised timezone when constructing a Moment
1.5.1
- added:
- getMomentsByWeekdays()
- getWeekday()
- getWeekOfYear()
- other:
- escaped text
1.5.0
-
added:
- startOf and endOf as implemented by moment.js
- get the quarter period of a given date
- setDay()
- getDay()
- setMonth()
- getMonth()
- setYear()
- getYear()
- getQuarter()
- setSecond()
- getSecond()
- setMinute()
- getMinute()
- setHour()
- getHour()
- added cloning()
- create a new mutable moment based of the given instance
- added to to indicate the interval of the given period
- = week of the year
- = month of the year
- = quarter of the year
- added a static class
- get the period for a given quarter in a given year
- fixed PHP's internal ordinal calculation (also in combination with moment.js formatting)
- e.g. for 21th week of the year shows now correct etc.
- you can now escape text by wrapping it in
- e.g. will be automatically transformed into
- removed:
- add()
- subtract()
1.4.0
- added:
- calendar format as implemented by moment.js
1.3.0
-
fixed:
- incompatibility w/ PHP 5.3
-
added:
- Exception throw as
- Date validation on instantiation:
- test for dates w/ format and
- throws MomentException on invalid dates
- addSeconds()
- addMinutes()
- addHours()
- addDays()
- addWeeks()
- addMonths()
- addYears()
- subtractSeconds()
- subtractMinutes()
- subtractHours()
- subtractDays()
- subtractWeeks()
- subtractMonths()
- subtractYears()
- deprecated:
- add()
- subtract()
License
Moment.php is freely distributable under the terms of the MIT license.
Copyright (c) 2017 Tino Ehrich
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.