PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Adapter / DateTimeAdapter.php
wp-staging / Framework / Adapter Last commit date
Database 1 day ago Database.php 1 day ago DatabaseInterface.php 1 year ago DateTimeAdapter.php 1 day ago Directory.php 1 day ago DirectoryInterface.php 1 year ago Maintenance.php 1 day ago PhpAdapter.php 1 day ago SourceDatabase.php 1 day ago WpAdapter.php 1 day ago
DateTimeAdapter.php
99 lines
1 <?php
2
3
4
5
6 namespace WPStaging\Framework\Adapter;
7
8 class DateTimeAdapter
9 {
10 const DEFAULT_TIME_FORMAT = 'H:i:s';
11
12
13 private $dateFormat;
14
15
16 private $timeFormat;
17
18
19 private $genericDateFormats = [
20
21 'F j, Y',
22 'Y-m-d',
23 'm/d/Y',
24 'd/m/Y',
25
26 'd-m-Y',
27 'm-d-Y',
28 'Y-m-d',
29 'Y/m/d',
30 ];
31
32 public function __construct()
33 {
34 $this->dateFormat = get_option('date_format');
35 $this->timeFormat = get_option('time_format');
36 }
37
38 public function getWPDateTimeFormat()
39 {
40 return $this->dateFormat . ' ' . $this->timeFormat;
41 }
42
43 public function getDateTimeFormat()
44 {
45 $dateFormat = $this->dateFormat;
46 $timeFormat = self::DEFAULT_TIME_FORMAT;
47
48 if (!$dateFormat) {
49 $dateFormat = 'Y/m/d';
50 }
51
52 $dateFormat = str_replace('F', 'M', $dateFormat);
53
54 return $dateFormat . ' ' . $timeFormat;
55 }
56
57
58
59
60
61 public function transformToWpFormat(\DateTime $dateTime)
62 {
63 return get_date_from_gmt($dateTime->format('Y-m-d H:i:s'), $this->getDateTimeFormat());
64 }
65
66
67
68
69
70 public function getDateTime($value)
71 {
72 $date = null;
73 foreach ($this->generateDefaultDateFormats() as $format) {
74 $date = \DateTime::createFromFormat($format, $value);
75 if ($date) {
76 break;
77 }
78 }
79
80 return $date ?: null;
81 }
82
83
84 private function generateDefaultDateFormats()
85 {
86 $formats = [
87 'U',
88 $this->getDateTimeFormat(),
89 $this->getWPDateTimeFormat(),
90 ];
91
92 foreach ($this->genericDateFormats as $format) {
93 $formats[] = $format . ' ' . self::DEFAULT_TIME_FORMAT;
94 }
95
96 return $formats;
97 }
98 }
99