OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/frontend/app/services/timezone-service.js

42 lines
1.1 KiB

module.exports = function(ConfigurationService, I18n) {
var TimezoneService = {
setupLocale: function() {
moment.lang(I18n.locale);
},
parseDate: function(date, format) {
var d = moment.utc(date, format);
if (ConfigurationService.isTimezoneSet()) {
d.local();
d.tz(ConfigurationService.timezone());
}
return d;
},
formattedDate: function(date) {
var format = ConfigurationService.dateFormatPresent() ? ConfigurationService.dateFormat() : 'L';
return TimezoneService.parseDate(date).format(format);
},
formattedTime: function(date) {
var format = ConfigurationService.timeFormatPresent() ? ConfigurationService.timeFormat() : 'LT';
return TimezoneService.parseDate(date).format(format);
},
formattedISODate: function(date) {
return TimezoneService.parseDate(date).format('YYYY-MM-DD');
},
isValid: function(date) {
var format = ConfigurationService.dateFormatPresent() ?
ConfigurationService.dateFormat() : 'L';
return moment(date, [format]).isValid();
}
};
return TimezoneService;
};