2016-11-14 16:16:51 +03:00
|
|
|
const parseDateFormats = [
|
|
|
|
'DD MMM YY @ HH:mm', 'DD MMM YY HH:mm',
|
|
|
|
'D MMM YY @ HH:mm', 'D MMM YY HH:mm',
|
|
|
|
'DD MMM YYYY @ HH:mm', 'DD MMM YYYY HH:mm',
|
|
|
|
'D MMM YYYY @ HH:mm', 'D MMM YYYY HH:mm',
|
|
|
|
'DD/MM/YY @ HH:mm', 'DD/MM/YY HH:mm',
|
|
|
|
'DD/MM/YYYY @ HH:mm', 'DD/MM/YYYY HH:mm',
|
|
|
|
'DD-MM-YY @ HH:mm', 'DD-MM-YY HH:mm',
|
|
|
|
'DD-MM-YYYY @ HH:mm', 'DD-MM-YYYY HH:mm',
|
|
|
|
'YYYY-MM-DD @ HH:mm', 'YYYY-MM-DD HH:mm',
|
|
|
|
'DD MMM @ HH:mm', 'DD MMM HH:mm',
|
|
|
|
'D MMM @ HH:mm', 'D MMM HH:mm'
|
|
|
|
];
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
const displayDateFormat = 'DD MMM YY @ HH:mm';
|
2014-04-20 18:48:34 +04:00
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
// Add missing timestamps
|
2015-10-28 14:36:45 +03:00
|
|
|
function verifyTimeStamp(dateString) {
|
2014-06-09 00:48:14 +04:00
|
|
|
if (dateString && !dateString.slice(-5).match(/\d+:\d\d/)) {
|
|
|
|
dateString += ' 12:00';
|
|
|
|
}
|
|
|
|
return dateString;
|
2015-10-28 14:36:45 +03:00
|
|
|
}
|
2014-06-09 00:48:14 +04:00
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
// Parses a string to a Moment
|
2016-06-08 14:06:07 +03:00
|
|
|
function parseDateString(value, timezone) {
|
|
|
|
// We need the timezone here, otherwise the date will be parsed
|
Timezones: Always use the timezone of blog setting
closes TryGhost/Ghost#6406
follow-up PR of #2
- adds a `timeZone` Service to provide the offset (=timezone reg. moment-timezone) of the users blog settings
- `gh-datetime-input` will read the offset of the timezone now and adjust the `publishedAt` date with it. This is the date which will be shown in the PSM 'Publish Date' field. When the user writes a new date/time, the offset is considered and will be deducted again before saving it to the model. This way, we always work with a UTC publish date except for this input field.
- gets `availableTimezones` from `configuration/timezones` API endpoint
- adds a `moment-utc` transform on all date attr (`createdAt`, `updatedAt`, `publishedAt`, `unsubscribedAt` and `lastLogin`) to only work with UTC times on serverside
- when switching the timezone in the select box, the user will be shown the local time of the selected timezone
- `createdAt`-property in `gh-user-invited` returns now `moment(createdAt).fromNow()` as `createdAt` is a moment date already
- added clock service to show actual time ticking below select box
- default timezone is '(GMT) Greenwich Mean Time : Dublin, Edinburgh, London'
- if no timezone is saved in the settings yet, the default value will be used
- shows the local time in 'Publish Date' in PSM by default, until user overwrites it
- adds dependency `moment-timezone 0.5.4` to `bower.json`
---------
**Tests:**
- sets except for clock service in test env
- adds fixtures to mirage
- adds `service.ajax` and `service:ghostPaths` to navigation-test.js
- adds unit test for `gh-format-timeago` helper
- updates acceptance test `general-setting`
- adds acceptance test for `editor`
- adds integration tests for `services/config` and `services/time-zone`
---------
**Todos:**
- [ ] Integration tests: ~~`services/config`~~, ~~`services/time-zone`~~, `components/gh-datetime-input`
- [x] Acceptance test: `editor`
- [ ] Unit tests: `utils/date-formatting`
- [ ] write issue for renaming date properties (e. g. `createdAt` to `createdAtUTC`) and translate those for server side with serializers
2016-02-02 10:04:40 +03:00
|
|
|
// in UTC timezone
|
2016-06-08 14:06:07 +03:00
|
|
|
moment.tz.setDefault(timezone);
|
Timezones: Always use the timezone of blog setting
closes TryGhost/Ghost#6406
follow-up PR of #2
- adds a `timeZone` Service to provide the offset (=timezone reg. moment-timezone) of the users blog settings
- `gh-datetime-input` will read the offset of the timezone now and adjust the `publishedAt` date with it. This is the date which will be shown in the PSM 'Publish Date' field. When the user writes a new date/time, the offset is considered and will be deducted again before saving it to the model. This way, we always work with a UTC publish date except for this input field.
- gets `availableTimezones` from `configuration/timezones` API endpoint
- adds a `moment-utc` transform on all date attr (`createdAt`, `updatedAt`, `publishedAt`, `unsubscribedAt` and `lastLogin`) to only work with UTC times on serverside
- when switching the timezone in the select box, the user will be shown the local time of the selected timezone
- `createdAt`-property in `gh-user-invited` returns now `moment(createdAt).fromNow()` as `createdAt` is a moment date already
- added clock service to show actual time ticking below select box
- default timezone is '(GMT) Greenwich Mean Time : Dublin, Edinburgh, London'
- if no timezone is saved in the settings yet, the default value will be used
- shows the local time in 'Publish Date' in PSM by default, until user overwrites it
- adds dependency `moment-timezone 0.5.4` to `bower.json`
---------
**Tests:**
- sets except for clock service in test env
- adds fixtures to mirage
- adds `service.ajax` and `service:ghostPaths` to navigation-test.js
- adds unit test for `gh-format-timeago` helper
- updates acceptance test `general-setting`
- adds acceptance test for `editor`
- adds integration tests for `services/config` and `services/time-zone`
---------
**Todos:**
- [ ] Integration tests: ~~`services/config`~~, ~~`services/time-zone`~~, `components/gh-datetime-input`
- [x] Acceptance test: `editor`
- [ ] Unit tests: `utils/date-formatting`
- [ ] write issue for renaming date properties (e. g. `createdAt` to `createdAtUTC`) and translate those for server side with serializers
2016-02-02 10:04:40 +03:00
|
|
|
|
2014-06-09 00:48:14 +04:00
|
|
|
return value ? moment(verifyTimeStamp(value), parseDateFormats, true) : undefined;
|
2015-10-28 14:36:45 +03:00
|
|
|
}
|
2014-04-20 18:48:34 +04:00
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
// Formats a Date or Moment
|
2016-06-08 14:06:07 +03:00
|
|
|
function formatDate(value, timezone) {
|
|
|
|
// we output the date adjusted to the blog timezone selected in settings
|
|
|
|
return verifyTimeStamp(value ? moment(value).tz(timezone).format(displayDateFormat) : '');
|
2015-10-28 14:36:45 +03:00
|
|
|
}
|
2014-04-20 18:48:34 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
export {
|
|
|
|
parseDateString,
|
|
|
|
formatDate
|
|
|
|
};
|