CurrencyDataProvider.php
3 months ago
DateTimeFormatProvider.php
6 months ago
LanguageDataProvider.php
2 years ago
RegionDataProvider.php
1 year ago
DateTimeFormatProvider.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Intl\Data\Provider; |
| 10 | |
| 11 | /** |
| 12 | * Provides date and time formats. |
| 13 | */ |
| 14 | class DateTimeFormatProvider |
| 15 | { |
| 16 | public const DATETIME_FORMAT_LONG = 1; |
| 17 | public const DATETIME_FORMAT_SHORT = 2; |
| 18 | public const DATE_FORMAT_LONG = 10; |
| 19 | public const DATE_FORMAT_DAY_MONTH = 11; |
| 20 | public const DATE_FORMAT_SHORT = 12; |
| 21 | public const DATE_FORMAT_MONTH_SHORT = 13; |
| 22 | public const DATE_FORMAT_MONTH_LONG = 14; |
| 23 | public const DATE_FORMAT_YEAR = 15; |
| 24 | public const TIME_FORMAT = 20; |
| 25 | /** |
| 26 | * Returns the format pattern for the given format type |
| 27 | * |
| 28 | * @param int|string $format one of the format constants |
| 29 | * |
| 30 | * @return string |
| 31 | */ |
| 32 | public function getFormatPattern($format) |
| 33 | { |
| 34 | switch ($format) { |
| 35 | case self::DATETIME_FORMAT_LONG: |
| 36 | return 'EEEE, MMMM d, y HH:mm:ss'; |
| 37 | case self::DATETIME_FORMAT_SHORT: |
| 38 | return 'MMM d, y HH:mm:ss'; |
| 39 | case self::DATE_FORMAT_LONG: |
| 40 | return 'EEEE, MMMM d, y'; |
| 41 | case self::DATE_FORMAT_DAY_MONTH: |
| 42 | return 'E, MMM d'; |
| 43 | case self::DATE_FORMAT_SHORT: |
| 44 | return 'MMM d, y'; |
| 45 | case self::DATE_FORMAT_MONTH_SHORT: |
| 46 | return 'MMM y'; |
| 47 | case self::DATE_FORMAT_MONTH_LONG: |
| 48 | return 'MMMM y'; |
| 49 | case self::DATE_FORMAT_YEAR: |
| 50 | return 'y'; |
| 51 | case self::TIME_FORMAT: |
| 52 | return 'HH:mm:ss'; |
| 53 | } |
| 54 | return (string) $format; |
| 55 | } |
| 56 | /** |
| 57 | * Returns if time is present as 12 hour clock (eg am/pm) |
| 58 | * |
| 59 | * @return bool |
| 60 | */ |
| 61 | public function uses12HourClock() |
| 62 | { |
| 63 | return \false; |
| 64 | } |
| 65 | /** |
| 66 | * Returns interval format pattern for the given format type |
| 67 | * |
| 68 | * @param bool $short whether to return short or long format pattern |
| 69 | * @param string $maxDifference maximal difference in interval dates (Y, M or D) |
| 70 | * |
| 71 | * @return string |
| 72 | */ |
| 73 | public function getRangeFormatPattern($short = \false, $maxDifference = 'Y') |
| 74 | { |
| 75 | if ($short) { |
| 76 | return 'MMM d, y – MMM d, y'; |
| 77 | } |
| 78 | return 'MMMM d, y – MMMM d, y'; |
| 79 | } |
| 80 | } |
| 81 |