File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -1179,4 +1179,12 @@ public function __wakeup(): void
1179
1179
$ this ->timezone = new DateTimeZone ($ timezone );
1180
1180
parent ::__construct ($ this ->date , $ this ->timezone );
1181
1181
}
1182
+
1183
+ /**
1184
+ * Returns the datetime string ('Y-m-d H:i:s') that is safe to databases regardless of locale.
1185
+ */
1186
+ public function toDatabase (): string
1187
+ {
1188
+ return $ this ->format ('Y-m-d H:i:s ' );
1189
+ }
1182
1190
}
Original file line number Diff line number Diff line change @@ -1128,4 +1128,17 @@ public function testSetTestNowWithFaLocale()
1128
1128
1129
1129
Locale::setDefault ($ currentLocale );
1130
1130
}
1131
+
1132
+ public function testToDatabase ()
1133
+ {
1134
+ $ currentLocale = Locale::getDefault ();
1135
+ Locale::setDefault ('fa ' );
1136
+
1137
+ $ time = Time::parse ('2017-01-12 00:00 ' , 'America/Chicago ' );
1138
+
1139
+ $ this ->assertSame ('۲۰۱۷-۰۱-۱۲ ۰۰:۰۰:۰۰ ' , (string ) $ time );
1140
+ $ this ->assertSame ('2017-01-12 00:00:00 ' , $ time ->toDatabase ());
1141
+
1142
+ Locale::setDefault ($ currentLocale );
1143
+ }
1131
1144
}
You can’t perform that action at this time.
0 commit comments