Fixed ignore-timezone data-attribute
authorMarcel Werk <burntime@woltlab.com>
Wed, 28 Dec 2016 17:48:15 +0000 (18:48 +0100)
committerMarcel Werk <burntime@woltlab.com>
Wed, 28 Dec 2016 17:48:25 +0000 (18:48 +0100)
com.woltlab.wcf/templates/__messageFormPoll.tpl
com.woltlab.wcf/templates/__messageFormPollInline.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js

index ba43b177b5cfbdeee8709f26ded9dc4859edb712..c7f549086fc45089c00d7895c527280c2fd7ea88 100644 (file)
@@ -41,7 +41,7 @@
                                <label for="pollEndTime">{lang}wcf.poll.endTime{/lang}</label>
                        </dt>
                        <dd>
-                               <input type="datetime" name="pollEndTime" id="pollEndTime" value="{if $pollEndTime}{@$pollEndTime|date:'c'}{/if}" class="medium" data-ignore-timezone="true">
+                               <input type="datetime" name="pollEndTime" id="pollEndTime" value="{if $pollEndTime}{@$pollEndTime|date:'c'}{/if}" class="medium">
                                {if $errorField == 'pollEndTime'}
                                        <small class="innerError">
                                                {lang}wcf.poll.endTime.error.{@$errorType}{/lang}
index 3f7004b79a098caf01a3274bce2a093dccc37873..b0f9a5450e01d5b958d16edcf29698fcef521d1d 100644 (file)
@@ -38,7 +38,7 @@
                                <label for="pollEndTime_{$wysiwygSelector}">{lang}wcf.poll.endTime{/lang}</label>
                        </dt>
                        <dd>
-                               <input type="datetime" name="pollEndTime" id="pollEndTime_{$wysiwygSelector}" value="{if $pollEndTime}{@$pollEndTime|date:'c'}{/if}" class="medium" data-ignore-timezone="true">
+                               <input type="datetime" name="pollEndTime" id="pollEndTime_{$wysiwygSelector}" value="{if $pollEndTime}{@$pollEndTime|date:'c'}{/if}" class="medium">
                        </dd>
                </dl>
                <dl>
index 24ded4cb1b8216616aa5a3b567a9e9b165a54316..244bcb1c5f6383e13b284de34aee328b1528a3f2 100644 (file)
@@ -50,6 +50,7 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment
                                var isDateTime = (elAttr(element, 'type') === 'datetime');
                                var isTimeOnly = (isDateTime && elDataBool(element, 'time-only'));
                                var disableClear = elDataBool(element, 'disable-clear');
+                               var ignoreTimezone = isDateTime && elDataBool(element, 'ignore-timezone');
                                
                                elData(element, 'is-date-time', isDateTime);
                                elData(element, 'is-time-only', isTimeOnly);
@@ -63,6 +64,19 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment
                                                date.setHours(tmp[0], tmp[1]);
                                        }
                                        else {
+                                               if (ignoreTimezone) {
+                                                       var timezoneOffset = new Date(value).getTimezoneOffset();
+                                                       var timezone = (timezoneOffset > 0) ? '-' : '+'; // -120 equals GMT+0200
+                                                       timezoneOffset = Math.abs(timezoneOffset);
+                                                       var hours = (Math.floor(timezoneOffset / 60)).toString();
+                                                       var minutes = (timezoneOffset % 60).toString();
+                                                       timezone += (hours.length == 2) ? hours : '0' + hours;
+                                                       timezone += ':';
+                                                       timezone += (minutes.length == 2) ? minutes : '0' + minutes;
+                                                       
+                                                       value = value.replace(/[+-][0-9]{2}:[0-9]{2}$/, timezone);
+                                               }
+                                               
                                                date = new Date(value);
                                        }
                                        
@@ -111,6 +125,9 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment
                                        if (isTimeOnly) {
                                                shadowElement.value = DateUtil.format(date, 'H:i');
                                        }
+                                       else if (ignoreTimezone) {
+                                               shadowElement.value = DateUtil.format(date, 'Y-m-dTH:i:s');
+                                       }
                                        else {
                                                shadowElement.value = DateUtil.format(date, (isDateTime) ? 'c' : 'Y-m-d');
                                        }
@@ -170,6 +187,7 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment
                                        isDateTime: isDateTime,
                                        isEmpty: isEmpty,
                                        isTimeOnly: isTimeOnly,
+                                       ignoreTimezone: ignoreTimezone,
                                        
                                        onClose: null
                                });
@@ -483,6 +501,10 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment
                                        value = DateUtil.formatTime(date);
                                        shadowValue = DateUtil.format(date, 'H:i');
                                }
+                               else if (data.ignoreTimezone) {
+                                       value = DateUtil.formatDateTime(date);
+                                       shadowValue = DateUtil.format(date, 'Y-m-dTH:i:s');
+                               }
                                else {
                                        value = DateUtil.formatDateTime(date);
                                        shadowValue = DateUtil.format(date, 'c');
@@ -712,7 +734,18 @@ define(['DateUtil', 'Language', 'ObjectMap', 'Dom/ChangeListener', 'Ui/Alignment
                        elData(element, 'value', date.getTime());
                        element.value = DateUtil['formatDate' + (data.isDateTime ? 'Time' : '')](date);
                        
-                       data.shadow.value = DateUtil.format(date, (data.isDateTime ? 'c' : 'Y-m-d'));
+                       var format = '';
+                       if (data.ignoreTimezone) {
+                               format = 'Y-m-dTH:i:s';
+                       }
+                       else if (data.isDateTime) {
+                               format = 'c';
+                       }
+                       else {
+                               format = 'Y-m-d';
+                       }
+                       
+                       data.shadow.value = DateUtil.format(date, format);
                },
                
                /**