From b7baa776281139d350d3415d2560ec6d04d5714c Mon Sep 17 00:00:00 2001 From: Zeusking19 <zeusking19@poniverse.net> Date: Wed, 16 Dec 2015 17:02:01 +0000 Subject: [PATCH 1/3] Resolve #26 --- app/Album.php | 2 +- app/Playlist.php | 2 +- app/Track.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Album.php b/app/Album.php index f1c8c11d..6e69d40a 100644 --- a/app/Album.php +++ b/app/Album.php @@ -165,7 +165,7 @@ class Album extends Model 'track_count' => (int)$album->track_count, 'title' => $album->title, 'slug' => $album->slug, - 'created_at' => $album->created_at, + 'created_at' => $album->created_at->format('c'), 'stats' => [ 'views' => (int)$album->view_count, 'downloads' => (int)$album->download_count, diff --git a/app/Playlist.php b/app/Playlist.php index 042249e2..c2878c9b 100644 --- a/app/Playlist.php +++ b/app/Playlist.php @@ -122,7 +122,7 @@ class Playlist extends Model 'track_count' => $playlist->track_count, 'title' => $playlist->title, 'slug' => $playlist->slug, - 'created_at' => $playlist->created_at, + 'created_at' => $playlist->created_at->format('c'), 'is_public' => (bool)$playlist->is_public, 'stats' => [ 'views' => (int)$playlist->view_count, diff --git a/app/Track.php b/app/Track.php index 57e43298..984b576b 100644 --- a/app/Track.php +++ b/app/Track.php @@ -369,8 +369,8 @@ class Track extends Model 'is_explicit' => $track->is_explicit, 'is_downloadable' => $track->is_downloadable, 'is_published' => $track->isPublished(), - 'created_at' => $track->created_at, - 'published_at' => $track->published_at, + 'created_at' => $track->created_at->format('c'), + 'published_at' => $track->published_at->format('c'), 'duration' => $track->duration, 'genre_id' => $track->genre_id, 'track_type_id' => $track->track_type_id, From cac58df6f4803f0642bbbda3e9ad54f17a3bf8c7 Mon Sep 17 00:00:00 2001 From: Zeusking19 <zeusking19@poniverse.net> Date: Wed, 16 Dec 2015 18:52:40 +0000 Subject: [PATCH 2/3] Whoops - forgot something ;) --- app/Track.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Track.php b/app/Track.php index 984b576b..c452b020 100644 --- a/app/Track.php +++ b/app/Track.php @@ -308,7 +308,7 @@ class Track extends Model 'is_explicit' => (bool)$track->is_explicit, 'is_downloadable' => (bool)$track->is_downloadable, 'is_published' => (bool)$track->isPublished(), - 'published_at' => $track->published_at, + 'published_at' => $track->published_at->format('c'), 'duration' => $track->duration, 'genre' => $track->genre != null ? From 8aef88c2f19c8e282c7283f309bb2cdd3ae79330 Mon Sep 17 00:00:00 2001 From: Zeusking19 <zeusking19@poniverse.net> Date: Wed, 16 Dec 2015 18:56:47 +0000 Subject: [PATCH 3/3] Remove reliance on pfm-date.js, use Angular date instead --- app/Album.php | 2 +- app/Playlist.php | 2 +- app/Track.php | 2 +- public/templates/albums/show.html | 2 +- public/templates/playlists/show.html | 2 +- public/templates/tracks/show.html | 2 +- .../assets/scripts/app/filters/pfm-date.js | 222 ------------------ 7 files changed, 6 insertions(+), 228 deletions(-) delete mode 100644 resources/assets/scripts/app/filters/pfm-date.js diff --git a/app/Album.php b/app/Album.php index 6e69d40a..ec7e32b2 100644 --- a/app/Album.php +++ b/app/Album.php @@ -165,7 +165,7 @@ class Album extends Model 'track_count' => (int)$album->track_count, 'title' => $album->title, 'slug' => $album->slug, - 'created_at' => $album->created_at->format('c'), + 'created_at' => $album->created_at->toW3cString(), 'stats' => [ 'views' => (int)$album->view_count, 'downloads' => (int)$album->download_count, diff --git a/app/Playlist.php b/app/Playlist.php index c2878c9b..af85a634 100644 --- a/app/Playlist.php +++ b/app/Playlist.php @@ -122,7 +122,7 @@ class Playlist extends Model 'track_count' => $playlist->track_count, 'title' => $playlist->title, 'slug' => $playlist->slug, - 'created_at' => $playlist->created_at->format('c'), + 'created_at' => $playlist->created_at->toW3cString(), 'is_public' => (bool)$playlist->is_public, 'stats' => [ 'views' => (int)$playlist->view_count, diff --git a/app/Track.php b/app/Track.php index c452b020..52888f3b 100644 --- a/app/Track.php +++ b/app/Track.php @@ -308,7 +308,7 @@ class Track extends Model 'is_explicit' => (bool)$track->is_explicit, 'is_downloadable' => (bool)$track->is_downloadable, 'is_published' => (bool)$track->isPublished(), - 'published_at' => $track->published_at->format('c'), + 'published_at' => $track->published_at->toW3cString(), 'duration' => $track->duration, 'genre' => $track->genre != null ? diff --git a/public/templates/albums/show.html b/public/templates/albums/show.html index 967ddf10..c911f852 100644 --- a/public/templates/albums/show.html +++ b/public/templates/albums/show.html @@ -42,7 +42,7 @@ </div> <ul class="stats"> - <li>Published: <strong bo-text="album.created_at | pfmdate:'medium'"></strong></li> + <li>Published: <strong bo-text="album.created_at | date:'medium'"></strong></li> <li>Views: <strong bo-text="album.stats.views"></strong></li> <li>Downloads: <strong bo-text="album.stats.downloads"></strong></li> <li>Favourites: <strong bo-text="album.stats.favourites"></strong></li> diff --git a/public/templates/playlists/show.html b/public/templates/playlists/show.html index 2a22f983..5de7f689 100644 --- a/public/templates/playlists/show.html +++ b/public/templates/playlists/show.html @@ -41,7 +41,7 @@ </div> <ul class="stats"> - <li>Created: <strong bo-text="playlist.created_at | pfmdate:'medium'"></strong></li> + <li>Created: <strong bo-text="playlist.created_at | date:'medium'"></strong></li> <li>Views: <strong bo-text="playlist.stats.views"></strong></li> <li>Downloads: <strong bo-text="playlist.stats.downloads"></strong></li> <li>Favourites: <strong bo-text="playlist.stats.favourites"></strong></li> diff --git a/public/templates/tracks/show.html b/public/templates/tracks/show.html index a515e9ee..541808de 100644 --- a/public/templates/tracks/show.html +++ b/public/templates/tracks/show.html @@ -61,7 +61,7 @@ </div> <ul class="stats"> - <li>Published: <strong bo-text="track.published_at | pfmdate:'medium'"></strong></li> + <li>Published: <strong bo-text="track.published_at | date:'medium'"></strong></li> <li>Views: <strong bo-text="track.stats.views"></strong></li> <li>Plays: <strong bo-text="track.stats.plays"></strong></li> <li>Downloads: <strong bo-text="track.stats.downloads"></strong></li> diff --git a/resources/assets/scripts/app/filters/pfm-date.js b/resources/assets/scripts/app/filters/pfm-date.js deleted file mode 100644 index 99288f7a..00000000 --- a/resources/assets/scripts/app/filters/pfm-date.js +++ /dev/null @@ -1,222 +0,0 @@ -/* - If you're wondering, this is indeed a copy/paste of angular's date filter with all of its internal dependencies. - Why, you ask? Well, I needed to add lines 190 and 191, and didn't want to edit the source of angular itself. - Now this filter supports dates returned directly from Carbon. - */ - -angular.module('ponyfm').filter('pfmdate', [ - '$locale', - function($locale) { - function isString(value){return typeof value == 'string';} - function isNumber(value){return typeof value == 'number';} - - function isDate(value){ - if (!value) - return false; - - return Object.prototype.toString.apply(value) == '[object Date]'; - } - - function padNumber(num, digits, trim) { - var neg = ''; - if (num < 0) { - neg = '-'; - num = -num; - } - num = '' + num; - while(num.length < digits) num = '0' + num; - if (trim) - num = num.substr(num.length - digits); - return neg + num; - } - - function int(str) { - return parseInt(str, 10); - } - - function concat(array1, array2, index) { - return array1.concat([].slice.call(array2, index)); - } - - function isArrayLike(obj) { - if (!obj || (typeof obj.length !== 'number')) return false; - - // We have on object which has length property. Should we treat it as array? - if (typeof obj.hasOwnProperty != 'function' && - typeof obj.constructor != 'function') { - // This is here for IE8: it is a bogus object treat it as array; - return true; - } else { - return obj instanceof JQLite || // JQLite - (jQuery && obj instanceof jQuery) || // jQuery - toString.call(obj) !== '[object Object]' || // some browser native object - typeof obj.callee === 'function'; // arguments (on IE8 looks like regular obj) - } - } - - function isFunction(value){return typeof value == 'function';} - - function forEach(obj, iterator, context) { - var key; - if (obj) { - if (isFunction(obj)){ - for (key in obj) { - if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) { - iterator.call(context, obj[key], key); - } - } - } else if (obj.forEach && obj.forEach !== forEach) { - obj.forEach(iterator, context); - } else if (isArrayLike(obj)) { - for (key = 0; key < obj.length; key++) - iterator.call(context, obj[key], key); - } else { - for (key in obj) { - if (obj.hasOwnProperty(key)) { - iterator.call(context, obj[key], key); - } - } - } - } - return obj; - } - - var uppercase = function(string){return isString(string) ? string.toUpperCase() : string;}; - - var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/, - NUMBER_STRING = /^\d+$/; - - var DATE_FORMATS = { - yyyy: dateGetter('FullYear', 4), - yy: dateGetter('FullYear', 2, 0, true), - y: dateGetter('FullYear', 1), - MMMM: dateStrGetter('Month'), - MMM: dateStrGetter('Month', true), - MM: dateGetter('Month', 2, 1), - M: dateGetter('Month', 1, 1), - dd: dateGetter('Date', 2), - d: dateGetter('Date', 1), - HH: dateGetter('Hours', 2), - H: dateGetter('Hours', 1), - hh: dateGetter('Hours', 2, -12), - h: dateGetter('Hours', 1, -12), - mm: dateGetter('Minutes', 2), - m: dateGetter('Minutes', 1), - ss: dateGetter('Seconds', 2), - s: dateGetter('Seconds', 1), - // while ISO 8601 requires fractions to be prefixed with `.` or `,` - // we can be just safely rely on using `sss` since we currently don't support single or two digit fractions - sss: dateGetter('Milliseconds', 3), - EEEE: dateStrGetter('Day'), - EEE: dateStrGetter('Day', true), - a: ampmGetter, - Z: timeZoneGetter - }; - - function dateGetter(name, size, offset, trim) { - offset = offset || 0; - return function(date) { - var value = date['get' + name](); - if (offset > 0 || value > -offset) - value += offset; - if (value === 0 && offset == -12 ) value = 12; - return padNumber(value, size, trim); - }; - } - - function dateStrGetter(name, shortForm) { - return function(date, formats) { - var value = date['get' + name](); - var get = uppercase(shortForm ? ('SHORT' + name) : name); - - return formats[get][value]; - }; - } - - function timeZoneGetter(date) { - var zone = -1 * date.getTimezoneOffset(); - var paddedZone = (zone >= 0) ? "+" : ""; - - paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) + - padNumber(Math.abs(zone % 60), 2); - - return paddedZone; - } - - function ampmGetter(date, formats) { - return date.getHours() < 12 ? formats.AMPMS[0] : formats.AMPMS[1]; - } - - var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/; - function jsonStringToDate(string) { - var match; - if (match = string.match(R_ISO8601_STR)) { - var date = new Date(0), - tzHour = 0, - tzMin = 0, - dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear, - timeSetter = match[8] ? date.setUTCHours : date.setHours; - - if (match[9]) { - tzHour = int(match[9] + match[10]); - tzMin = int(match[9] + match[11]); - } - dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3])); - var h = int(match[4]||0) - tzHour; - var m = int(match[5]||0) - tzMin; - var s = int(match[6]||0); - var ms = Math.round(parseFloat('0.' + (match[7]||0)) * 1000); - timeSetter.call(date, h, m, s, ms); - return date; - } - return string; - } - - - return function(date, format) { - var text = '', - parts = [], - fn, match; - - if (typeof(date) == 'object' && date.date) { - date = date.date; - } - - format = format || 'mediumDate'; - format = $locale.DATETIME_FORMATS[format] || format; - if (isString(date)) { - if (NUMBER_STRING.test(date)) { - date = int(date); - } else { - date = jsonStringToDate(date); - } - } - - if (isNumber(date)) { - date = new Date(date); - } - - if (!isDate(date)) { - return date; - } - - while(format) { - match = DATE_FORMATS_SPLIT.exec(format); - if (match) { - parts = concat(parts, match, 1); - format = parts.pop(); - } else { - parts.push(format); - format = null; - } - } - - forEach(parts, function(value){ - fn = DATE_FORMATS[value]; - text += fn ? fn(date, $locale.DATETIME_FORMATS) - : value.replace(/(^'|'$)/g, '').replace(/''/g, "'"); - }); - - return text; - }; - }]);