-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from leepeuker/add-change-date-format-to-settings
Add way to change date format in frontend via settings page
- Loading branch information
Showing
13 changed files
with
227 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class AddDateFormatToUserTable extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE user DROP COLUMN date_format_id; | ||
SQL | ||
); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE user ADD COLUMN date_format_id TINYINT UNSIGNED DEFAULT 0 AFTER password; | ||
SQL | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\ValueObject; | ||
|
||
class DateFormat | ||
{ | ||
private const DEFAULT_ID = 0; | ||
|
||
private const FORMATS = [ | ||
self::DEFAULT_ID => [ | ||
self::KEY_PHP => 'y-m-d', | ||
self::KEY_JAVASCRIPT => 'yy-mm-dd', | ||
], | ||
1 => [ | ||
self::KEY_PHP => 'Y-m-d', | ||
self::KEY_JAVASCRIPT => 'yyyy-mm-dd', | ||
], | ||
2 => [ | ||
self::KEY_PHP => 'd.m.y', | ||
self::KEY_JAVASCRIPT => 'dd.mm.yy', | ||
], | ||
3 => [ | ||
self::KEY_PHP => 'd.m.Y', | ||
self::KEY_JAVASCRIPT => 'dd.mm.yyyy', | ||
], | ||
]; | ||
|
||
private const KEY_JAVASCRIPT = 'javascript'; | ||
|
||
private const KEY_PHP = 'php'; | ||
|
||
public static function getFormats() : array | ||
{ | ||
return self::FORMATS; | ||
} | ||
|
||
public static function getJavascriptById(int $id) : string | ||
{ | ||
if (isset(self::FORMATS[$id]) === false) { | ||
throw new \RuntimeException('Id does not exist: ' . $id); | ||
} | ||
|
||
return self::FORMATS[$id][self::KEY_JAVASCRIPT]; | ||
} | ||
|
||
public static function getJavascriptDefault() : string | ||
{ | ||
return self::getJavascriptById(self::DEFAULT_ID); | ||
} | ||
|
||
public static function getPhpById(int $offset) : string | ||
{ | ||
if (isset(self::FORMATS[$offset]) === false) { | ||
throw new \RuntimeException('Id does not exist: ' . $offset); | ||
} | ||
|
||
return self::FORMATS[$offset][self::KEY_PHP]; | ||
} | ||
|
||
public static function getPhpDefault() : string | ||
{ | ||
return self::getPhpById(self::DEFAULT_ID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.