TimezoneInterface.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Stdlib\DateTime;
  7. use Magento\Framework\Exception\LocalizedException;
  8. /**
  9. * Timezone Interface
  10. * @api
  11. * @since 100.0.2
  12. */
  13. interface TimezoneInterface
  14. {
  15. /**
  16. * Return path to default timezone
  17. *
  18. * @return string
  19. */
  20. public function getDefaultTimezonePath();
  21. /**
  22. * Retrieve timezone code
  23. *
  24. * @return string
  25. */
  26. public function getDefaultTimezone();
  27. /**
  28. * Retrieve ISO date format
  29. *
  30. * @param int $type
  31. * @return string
  32. */
  33. public function getDateFormat($type = \IntlDateFormatter::SHORT);
  34. /**
  35. * Retrieve short date format with 4-digit year
  36. *
  37. * @return string
  38. */
  39. public function getDateFormatWithLongYear();
  40. /**
  41. * Retrieve ISO time format
  42. *
  43. * @param string $type
  44. * @return string
  45. */
  46. public function getTimeFormat($type = null);
  47. /**
  48. * Retrieve ISO datetime format
  49. *
  50. * @param string $type
  51. * @return string
  52. */
  53. public function getDateTimeFormat($type);
  54. /**
  55. * Create \DateTime object for current locale
  56. *
  57. * @param mixed $date
  58. * @param string $locale
  59. * @param bool $useTimezone
  60. * @param bool $includeTime
  61. * @return \DateTime
  62. */
  63. public function date($date = null, $locale = null, $useTimezone = true, $includeTime = true);
  64. /**
  65. * Create \DateTime object with date converted to scope timezone and scope Locale
  66. *
  67. * @param mixed $scope Information about scope
  68. * @param string|integer|\DateTime|array|null $date date in UTC
  69. * @param boolean $includeTime flag for including time to date
  70. * @return \DateTime
  71. */
  72. public function scopeDate($scope = null, $date = null, $includeTime = false);
  73. /**
  74. * Get scope timestamp
  75. *
  76. * Timestamp will be built with scope timezone settings
  77. *
  78. * @param mixed $scope
  79. * @return int
  80. */
  81. public function scopeTimeStamp($scope = null);
  82. /**
  83. * Format date using current locale options and time zone.
  84. *
  85. * @param \DateTime|null $date
  86. * @param int $format
  87. * @param bool $showTime
  88. * @return string
  89. */
  90. public function formatDate(
  91. $date = null,
  92. $format = \IntlDateFormatter::SHORT,
  93. $showTime = false
  94. );
  95. /**
  96. * Gets the scope config timezone
  97. *
  98. * @param string $scopeType
  99. * @param string $scopeCode
  100. * @return string
  101. */
  102. public function getConfigTimezone($scopeType = null, $scopeCode = null);
  103. /**
  104. * Checks if current date of the given scope (in the scope timezone) is within the range
  105. *
  106. * @param int|string|\Magento\Framework\App\ScopeInterface $scope
  107. * @param string|null $dateFrom
  108. * @param string|null $dateTo
  109. * @return bool
  110. */
  111. public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null);
  112. /**
  113. * Format date according to date and time formats, locale, timezone and pattern.
  114. *
  115. * @param string|\DateTimeInterface $date
  116. * @param int $dateType
  117. * @param int $timeType
  118. * @param string|null $locale
  119. * @param string|null $timezone
  120. * @param string|null $pattern
  121. * @return string
  122. */
  123. public function formatDateTime(
  124. $date,
  125. $dateType = \IntlDateFormatter::SHORT,
  126. $timeType = \IntlDateFormatter::SHORT,
  127. $locale = null,
  128. $timezone = null,
  129. $pattern = null
  130. );
  131. /**
  132. * Convert date from config timezone to UTC.
  133. *
  134. * If pass \DateTime object as argument be sure that timezone is the same with config timezone
  135. *
  136. * @param string|\DateTimeInterface $date
  137. * @param string $format
  138. * @return string
  139. * @throws LocalizedException
  140. * @since 100.1.0
  141. */
  142. public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s');
  143. }