JavaScript: Display positive numbers with the plus sign but not string

833 views Asked by At

Using TimePiker I want to set timezone +840:

var sign = '+';
var totalMin = 840;
$('#timeStart').timepicker({
                showTimezone: true,
                timeFormat: "hh:mm TT",
                timezoneList: 
              [
                { value: -720, 'label': '(GMT-12:00) International Date Line West' },
                   ....
                { value: +840, 'label': '(GMT+14:00) Time in Samoa' }
              ],
          timezone:sign + totalMin
        });

If I set timezone:totalMin => timezone is not set

timezone:sign + totalMin returned string "+840" and timezone is not set, How I can to set positive number with + sing but not string

1

There are 1 answers

0
Alex On BEST ANSWER

I don't know if this is good solution but in case when is plus I set like this

    var sign = '+';
    var totalMin = 840;
if(sign=='+'){
    $('#timeStart').timepicker({
                    showTimezone: true,
                    timeFormat: "hh:mm TT",
                    timezoneList: 
                  [
                    { value: -720, 'label': '(GMT-12:00) International Date Line West' },
                       ....
                    { value: +840, 'label': '(GMT+14:00) Time in Samoa' }
                  ],
              timezone:+ totalMin
            });
}
else{
$('#timeStart').timepicker({
                    showTimezone: true,
                    timeFormat: "hh:mm TT",
                    timezoneList: 
                  [
                    { value: -720, 'label': '(GMT-12:00) International Date Line West' },
                       ....
                    { value: +840, 'label': '(GMT+14:00) Time in Samoa' }
                  ],
              timezone: totalMin
            });
}

maybe exist another