Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Jacobsen 438 posts 1818 karma points
    Dec 21, 2018 @ 12:57
    Bo Jacobsen
    0

    dateVal.locale is not a function

    Hey all.

    After i upgrade Umbraco CMS from version 7.4.0 to 7.12.4. I found out that every date picker gives this dateVal.locale is not a function error.

    enter image description here

    enter image description here

    umbraco.services.js where the error is from.

    angular.module('umbraco.services').factory('versionHelper', versionHelper);
    function dateHelper() {
        return {
            convertToServerStringTime: function (momentLocal, serverOffsetMinutes, format) {
                //get the formatted offset time in HH:mm (server time offset is in minutes)
                var formattedOffset = (serverOffsetMinutes > 0 ? '+' : '-') + moment().startOf('day').minutes(Math.abs(serverOffsetMinutes)).format('HH:mm');
                var server = moment.utc(momentLocal).utcOffset(formattedOffset);
                return server.format(format ? format : 'YYYY-MM-DD HH:mm:ss');
            },
            convertToLocalMomentTime: function (strVal, serverOffsetMinutes) {
                //get the formatted offset time in HH:mm (server time offset is in minutes)
                var formattedOffset = (serverOffsetMinutes > 0 ? '+' : '-') + moment().startOf('day').minutes(Math.abs(serverOffsetMinutes)).format('HH:mm');
                //if the string format already denotes that it's in "Roundtrip UTC" format (i.e. "2018-02-07T00:20:38.173Z")
                //otherwise known as https://en.wikipedia.org/wiki/ISO_8601. This is the default format returned from the server
                //since that is the default formatter for newtonsoft.json. When it is in this format, we need to tell moment
                //to load the date as UTC so it's not changed, otherwise load it normally
                var isoFormat;
                if (strVal.indexOf('T') > -1 && strVal.endsWith('Z')) {
                    isoFormat = moment.utc(strVal).format('YYYY-MM-DDTHH:mm:ss') + formattedOffset;
                } else {
                    isoFormat = moment(strVal).format('YYYY-MM-DDTHH:mm:ss') + formattedOffset;
                }
                //create a moment with the iso format which will include the offset with the correct time
                // then convert it to local time
                return moment.parseZone(isoFormat).local();
            },
            getLocalDate: function (date, culture, format) {
                if (date) {
                    var dateVal;
                    var serverOffset = Umbraco.Sys.ServerVariables.application.serverTimeOffset;
                    var localOffset = new Date().getTimezoneOffset();
                    var serverTimeNeedsOffsetting = -serverOffset !== localOffset;
                    if (serverTimeNeedsOffsetting) {
                        dateVal = this.convertToLocalMomentTime(date, serverOffset);
                    } else {
                        dateVal = moment(date, 'YYYY-MM-DD HH:mm:ss');
                    }
                    return dateVal.locale(culture).format(format); // <-- THIS LINE
                }
            }
        };
    }
    

    umbraco.directives.js where the service is called.

    userService.getCurrentUser().then(function (currentUser) {
        scope.node.createDateFormatted = dateHelper.getLocalDate(scope.node.createDate, currentUser.locale, 'LLL'); // <--- THIS LINE
        scope.node.releaseDateYear = scope.node.releaseDate ? ucfirst(dateHelper.getLocalDate(scope.node.releaseDate, currentUser.locale, 'YYYY')) : null;
        scope.node.releaseDateMonth = scope.node.releaseDate ? ucfirst(dateHelper.getLocalDate(scope.node.releaseDate, currentUser.locale, 'MMMM')) : null;
        scope.node.releaseDateDayNumber = scope.node.releaseDate ? ucfirst(dateHelper.getLocalDate(scope.node.releaseDate, currentUser.locale, 'DD')) : null;
        scope.node.releaseDateDay = scope.node.releaseDate ? ucfirst(dateHelper.getLocalDate(scope.node.releaseDate, currentUser.locale, 'dddd')) : null;
        scope.node.releaseDateTime = scope.node.releaseDate ? ucfirst(dateHelper.getLocalDate(scope.node.releaseDate, currentUser.locale, 'HH:mm')) : null;
        scope.node.removeDateYear = scope.node.removeDate ? ucfirst(dateHelper.getLocalDate(scope.node.removeDate, currentUser.locale, 'YYYY')) : null;
        scope.node.removeDateMonth = scope.node.removeDate ? ucfirst(dateHelper.getLocalDate(scope.node.removeDate, currentUser.locale, 'MMMM')) : null;
        scope.node.removeDateDayNumber = scope.node.removeDate ? ucfirst(dateHelper.getLocalDate(scope.node.removeDate, currentUser.locale, 'DD')) : null;
        scope.node.removeDateDay = scope.node.removeDate ? ucfirst(dateHelper.getLocalDate(scope.node.removeDate, currentUser.locale, 'dddd')) : null;
        scope.node.removeDateTime = scope.node.removeDate ? ucfirst(dateHelper.getLocalDate(scope.node.removeDate, currentUser.locale, 'HH:mm')) : null;
    });
    

    I have tried to replace the the folder umbraco and umbraco_client with a clean 7.12.4 package, with no luck. Am i missing something obvious?

  • Bo Jacobsen 438 posts 1818 karma points
    Dec 21, 2018 @ 13:03
    Bo Jacobsen
    0

    When i read my own message for the 15th time. I think it might be something to do with the created date on a document and not the date picker it self.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies