{"action":"created","issue":{"url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4449","repository_url":"https://api.github.com/repos/silverstripe/silverstripe-framework","labels_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4449/labels{/name}","comments_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4449/comments","events_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4449/events","html_url":"https://github.com/silverstripe/silverstripe-framework/pull/4449","id":97865194,"number":4449,"title":"ENH: moving hardcoded nice date/time formats to config","user":{"login":"IgorNadj","id":667652,"avatar_url":"https://avatars.githubusercontent.com/u/667652?v=3","gravatar_id":"","url":"https://api.github.com/users/IgorNadj","html_url":"https://github.com/IgorNadj","followers_url":"https://api.github.com/users/IgorNadj/followers","following_url":"https://api.github.com/users/IgorNadj/following{/other_user}","gists_url":"https://api.github.com/users/IgorNadj/gists{/gist_id}","starred_url":"https://api.github.com/users/IgorNadj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IgorNadj/subscriptions","organizations_url":"https://api.github.com/users/IgorNadj/orgs","repos_url":"https://api.github.com/users/IgorNadj/repos","events_url":"https://api.github.com/users/IgorNadj/events{/privacy}","received_events_url":"https://api.github.com/users/IgorNadj/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-29T05:43:33Z","updated_at":"2016-04-27T23:51:39Z","closed_at":"2016-04-19T07:30:41Z","pull_request":{"url":"https://api.github.com/repos/silverstripe/silverstripe-framework/pulls/4449","html_url":"https://github.com/silverstripe/silverstripe-framework/pull/4449","diff_url":"https://github.com/silverstripe/silverstripe-framework/pull/4449.diff","patch_url":"https://github.com/silverstripe/silverstripe-framework/pull/4449.patch"},"body":"I was using Date.Nice() in my template today, and wanted it to have an even nicer format, but soon found that it was hardcoded, and I could only use Date.Format('...'), copy-pasting it across my template files.\r\n\r\nIt's generally good practice to move the default date format out to a config somewhere, so I have done so in this commit. The default stays the same, but if you want to change it, you just pop into your site's config.yml and do:\r\n\r\nDate:\r\n  niceFormat: '...'\r\nDatetime:\r\n  niceFormat: '...'\r\nTime:\r\n  niceFormat: '...'\r\n\r\nBelow is some code that might be handy for the people reading this if they want to play around with this. Thanks,\r\nIgor\r\n\r\n--------------------------------------------------------------\r\n// mysite/code/TestDateFormat.php\r\n<?php \r\n\r\nclass TestDateFormat extends Controller {\r\n\t\r\n\tpublic function index(){\r\n\t\techo '<pre>';\r\n\t\t\r\n\t\t$objs = array(\r\n\t\t\t'Date'        => new Date(),\r\n\t\t\t'SS_Datetime' => new SS_Datetime(),\r\n\t\t\t'Time'        => new Time(),\r\n\t\t);\r\n\t\t$objs['Date']->setValue('2015-07-29');\r\n\t\t$objs['SS_Datetime']->setValue('2015-07-29 17:15:55');\r\n\t\t$objs['Time']->setValue('17:15:55');\r\n\t\t\r\n\t\t$newNiceFormats = array(\r\n\t\t\t'Date'        => 'd F Y',\r\n\t\t\t'SS_Datetime' => 'd F Y, H:i:s',\r\n\t\t\t'Time'        => 'H:i:s',\t\r\n\t\t);\r\n\t\t\r\n\t\tforeach($objs as $class => $obj){\r\n\t\t\techo PHP_EOL.PHP_EOL.'CLASS: '.$class.PHP_EOL;\r\n\t\t\t\r\n\t\t\t$defaultNiceFormat = Config::inst()->get($class, 'niceFormat');\r\n\t\t\techo 'Default niceFormat is: \"'.$defaultNiceFormat.'\"'.PHP_EOL;\r\n\t\t\techo 'getValue() = \"'.$obj->getValue().'\"'.PHP_EOL;\r\n\t\t\techo 'Nice()     = \"'.$obj->Nice().'\"'.PHP_EOL.PHP_EOL;\r\n\t\t\t\r\n\t\t\t$newNiceFormat = $newNiceFormats[$class];\r\n\t\t\tConfig::inst()->update($class, 'niceFormat', $newNiceFormat);\r\n\t\t\techo 'New niceFormat is: \"'.$newNiceFormat.'\"'.PHP_EOL;\r\n\t\t\techo 'Nice()     = \"'.$obj->Nice().'\"'.PHP_EOL.PHP_EOL;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tdie;\r\n\t\t\r\n\t}\r\n\t\r\n}\r\n\r\n// mysite/_config.php\r\nConfig::inst()->update('Director', 'rules', array('testdateformat' => 'TestDateFormat')); // now go to http://localhost/testdateformat"},"comment":{"url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/comments/215266818","html_url":"https://github.com/silverstripe/silverstripe-framework/pull/4449#issuecomment-215266818","issue_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4449","id":215266818,"user":{"login":"tractorcow","id":936064,"avatar_url":"https://avatars.githubusercontent.com/u/936064?v=3","gravatar_id":"","url":"https://api.github.com/users/tractorcow","html_url":"https://github.com/tractorcow","followers_url":"https://api.github.com/users/tractorcow/followers","following_url":"https://api.github.com/users/tractorcow/following{/other_user}","gists_url":"https://api.github.com/users/tractorcow/gists{/gist_id}","starred_url":"https://api.github.com/users/tractorcow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tractorcow/subscriptions","organizations_url":"https://api.github.com/users/tractorcow/orgs","repos_url":"https://api.github.com/users/tractorcow/repos","events_url":"https://api.github.com/users/tractorcow/events{/privacy}","received_events_url":"https://api.github.com/users/tractorcow/received_events","type":"User","site_admin":false},"created_at":"2016-04-27T23:51:39Z","updated_at":"2016-04-27T23:51:39Z","body":"@IgorNadj please link to the PR when you create it."}}