@mediafly/js-ui 51.3.2 → 51.3.3-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/lib/constants/constants.js +2 -1
- package/lib/constants/constants.js.map +1 -1
- package/lib/date-input/date-input.js +33 -12
- package/lib/date-input/date-input.js.map +1 -1
- package/lib/date-input/validate-date.js +12 -8
- package/lib/date-input/validate-date.js.map +1 -1
- package/lib/date-time-zone-picker/date-time-zone-factory.js +62 -49
- package/lib/date-time-zone-picker/date-time-zone-factory.js.map +1 -1
- package/lib/date-time-zone-picker/date-time-zone-picker.html +1 -1
- package/lib/date-time-zone-picker/date-time-zone-picker.js +82 -37
- package/lib/date-time-zone-picker/date-time-zone-picker.js.map +1 -1
- package/lib/date-time-zone-picker/datepicker.html +1 -2
- package/lib/date-time-zone-picker/datepicker.js +71 -19
- package/lib/date-time-zone-picker/datepicker.js.map +1 -1
- package/lib/date-time-zone-picker/time-format-filter.js +6 -6
- package/lib/date-time-zone-picker/time-format-filter.js.map +1 -1
- package/lib/date-time-zone-picker/timepicker.js +35 -20
- package/lib/date-time-zone-picker/timepicker.js.map +1 -1
- package/lib/time-input/time-input.js +27 -23
- package/lib/time-input/time-input.js.map +1 -1
- package/lib/time-input/validate-time.js +6 -2
- package/lib/time-input/validate-time.js.map +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +166 -24
- package/package.json +4 -4
- package/src/components/constants/constants.js +2 -1
- package/src/components/date-input/date-input.js +31 -12
- package/src/components/date-input/validate-date.js +14 -10
- package/src/components/date-time-zone-picker/date-time-zone-factory.ts +62 -49
- package/src/components/date-time-zone-picker/date-time-zone-picker.html +1 -1
- package/src/components/date-time-zone-picker/date-time-zone-picker.ts +87 -44
- package/src/components/date-time-zone-picker/datepicker.html +1 -2
- package/src/components/date-time-zone-picker/datepicker.ts +76 -20
- package/src/components/date-time-zone-picker/time-format-filter.ts +6 -6
- package/src/components/date-time-zone-picker/timepicker.js +46 -28
- package/src/components/time-input/time-input.js +27 -24
- package/src/components/time-input/validate-time.js +6 -2
- package/src/index.spec.js +1 -1
- package/webpack.config.js +6 -0
- package/tsconfig.tsbuildinfo +0 -7221
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import angular from 'angular'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import
|
|
3
|
+
import { DateTime } from 'luxon'
|
|
4
4
|
|
|
5
5
|
angular.module('app').factory('dateTimeZoneFactory', function dateTimeZoneFactory() {
|
|
6
6
|
|
|
@@ -38,44 +38,58 @@ angular.module('app').factory('dateTimeZoneFactory', function dateTimeZoneFactor
|
|
|
38
38
|
{ value: 12, zone: 'NZST - New Zealand Standard Time', display: 'NZST' }
|
|
39
39
|
]
|
|
40
40
|
|
|
41
|
-
// using string validate on the datepicker gives us more control
|
|
41
|
+
// using string validate on the datepicker gives us more control with luxon's parsing
|
|
42
42
|
const validDateFormats = [
|
|
43
|
-
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'
|
|
56
|
-
'
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
'
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
'
|
|
66
|
-
'
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
'
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
'
|
|
78
|
-
'
|
|
43
|
+
// Full month name formats (MMMM)
|
|
44
|
+
'd-MMMM-yyyy',
|
|
45
|
+
'd-MM-yyyy',
|
|
46
|
+
'd-M-yyyy',
|
|
47
|
+
'MMMM-d-yyyy',
|
|
48
|
+
'MM-d-yyyy',
|
|
49
|
+
'M-d-yyyy',
|
|
50
|
+
'd/MMMM/yyyy',
|
|
51
|
+
'd/MM/yyyy',
|
|
52
|
+
'd/M/yyyy',
|
|
53
|
+
'MMMM/d/yyyy',
|
|
54
|
+
'MM/d/yyyy',
|
|
55
|
+
'M/d/yyyy',
|
|
56
|
+
'd.MMMM.yyyy',
|
|
57
|
+
'd.MM.yyyy',
|
|
58
|
+
'd.M.yyyy',
|
|
59
|
+
'MMMM.d.yyyy',
|
|
60
|
+
'MM.d.yyyy',
|
|
61
|
+
'M.d.yyyy',
|
|
62
|
+
'd-MMMM-yy',
|
|
63
|
+
'd-MM-yy',
|
|
64
|
+
'd-M-yy',
|
|
65
|
+
'MMMM-d-yy',
|
|
66
|
+
'MM-d-yy',
|
|
67
|
+
'M-d-yy',
|
|
68
|
+
'd/MMMM/yy',
|
|
69
|
+
'd/MM/yy',
|
|
70
|
+
'd/M/yy',
|
|
71
|
+
'MMMM/d/yy',
|
|
72
|
+
'MM/d/yy',
|
|
73
|
+
'M/d/yy',
|
|
74
|
+
'd.MMMM.yy',
|
|
75
|
+
'd.MM.yy',
|
|
76
|
+
'd.M.yy',
|
|
77
|
+
'MMMM.d.yy',
|
|
78
|
+
'MM.d.yy',
|
|
79
|
+
'M.d.yy',
|
|
80
|
+
// Abbreviated month name formats (MMM)
|
|
81
|
+
'd-MMM-yyyy',
|
|
82
|
+
'MMM-d-yyyy',
|
|
83
|
+
'd/MMM/yyyy',
|
|
84
|
+
'MMM/d/yyyy',
|
|
85
|
+
'd.MMM.yyyy',
|
|
86
|
+
'MMM.d.yyyy',
|
|
87
|
+
'd-MMM-yy',
|
|
88
|
+
'MMM-d-yy',
|
|
89
|
+
'd/MMM/yy',
|
|
90
|
+
'MMM/d/yy',
|
|
91
|
+
'd.MMM.yy',
|
|
92
|
+
'MMM.d.yy'
|
|
79
93
|
]
|
|
80
94
|
|
|
81
95
|
|
|
@@ -85,28 +99,27 @@ angular.module('app').factory('dateTimeZoneFactory', function dateTimeZoneFactor
|
|
|
85
99
|
|
|
86
100
|
validDateFormats,
|
|
87
101
|
|
|
88
|
-
getTimeZone(
|
|
102
|
+
getTimeZone(dateTime) {
|
|
89
103
|
|
|
90
|
-
if (
|
|
104
|
+
if (dateTime && dateTime.isValid) {
|
|
91
105
|
|
|
92
106
|
// Get the timezone offset in hours and adjust the sign
|
|
93
|
-
let zoneOffset =
|
|
107
|
+
let zoneOffset = dateTime.offset / 60
|
|
94
108
|
|
|
95
109
|
// consider a shift for DST
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
const isDST = moment(momentDate.format()).isDST()
|
|
110
|
+
// create a fresh DateTime to check if DST is in effect
|
|
111
|
+
const isDST = DateTime.fromISO(dateTime.toISO()).isInDST
|
|
99
112
|
|
|
100
|
-
// at this point
|
|
101
|
-
// so for example if we are UTC -6 AND we are DST, then our
|
|
113
|
+
// at this point zoneOffset is our true offset from UTC 0
|
|
114
|
+
// so for example if we are UTC -6 AND we are DST, then our dateTime is really "Mountain Time" which is -7
|
|
102
115
|
// during the winter but is -6 during DST -- if we want to consistently show the label 'MST' for this date
|
|
103
|
-
// we need to select -7 although the offset is -6 (or subtracting 1 from our
|
|
116
|
+
// we need to select -7 although the offset is -6 (or subtracting 1 from our actual utc output)
|
|
104
117
|
zoneOffset = (isDST) ? zoneOffset - 1 : zoneOffset
|
|
105
118
|
|
|
106
119
|
// NOTE: The above DST adjustment is somewhat arbitrary.
|
|
107
120
|
// isDST() cannot be globally accurate as it works purely off a date and an offset.
|
|
108
|
-
// No actual timezone information is used except for
|
|
109
|
-
// Recommendation to switch to
|
|
121
|
+
// No actual timezone information is used except for assumptions made from the users current locale.
|
|
122
|
+
// Recommendation to switch to luxon's timezone handling in the future.
|
|
110
123
|
|
|
111
124
|
return this.getTimeZoneByOffset(zoneOffset)
|
|
112
125
|
}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
<!-- If the time is disabled, show plain text instead of controls -->
|
|
31
31
|
<div class="o-col-xs-7" ng-show="type === 'datetime' && dateMoment && isDisabled">
|
|
32
32
|
<div class="pull-left disabled">
|
|
33
|
-
<span>{{ parentMoment.
|
|
33
|
+
<span>{{ parentMoment.toFormat('hh:mm a') }} {{ (timeZone) ? timeZone.display : '' }}</span>
|
|
34
34
|
</div>
|
|
35
35
|
</div>
|
|
36
36
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import angular from 'angular'
|
|
2
|
-
import
|
|
2
|
+
import { DateTime } from 'luxon'
|
|
3
3
|
|
|
4
4
|
// This type is necessary because the directive link function expects something
|
|
5
5
|
// conforming to ng.IController, but we want the types from ng.INgModelController
|
|
@@ -23,52 +23,83 @@ angular.module('app').directive('mflyDateTimeZonePicker', ['dateTimeZoneFactory'
|
|
|
23
23
|
template: require('./date-time-zone-picker.html'),
|
|
24
24
|
link($scope: ScopeKeyValuePair, _element, _attr, ngModelCtrl: PatchedNgModelController) {
|
|
25
25
|
|
|
26
|
-
// Init function creates
|
|
27
|
-
// These
|
|
28
|
-
// timezone object is also created but is not a
|
|
29
|
-
// Each component only alters its respective
|
|
26
|
+
// Init function creates DateTime dates from our utc string provided by the API
|
|
27
|
+
// These DateTime dates are bound to the datepicker and timepicker (the
|
|
28
|
+
// timezone object is also created but is not a DateTime)
|
|
29
|
+
// Each component only alters its respective DateTime date, then tells this
|
|
30
30
|
// component when a change is made
|
|
31
31
|
// When a change is made, this component combines the 3 datetime elements
|
|
32
32
|
// and sends a utc string back to the api
|
|
33
33
|
// ------------------------------------------------------------------
|
|
34
34
|
function initParentMomentFromAPI(value) {
|
|
35
35
|
|
|
36
|
-
// Create a base
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
// Create a base DateTime and bound copies for each child component.
|
|
37
|
+
if (value instanceof Date) {
|
|
38
|
+
$scope.parentMoment = DateTime.fromJSDate(value)
|
|
39
|
+
} else if (typeof value === 'string') {
|
|
40
|
+
// Parse with setZone: true to preserve the offset from the string
|
|
41
|
+
const dt = DateTime.fromISO(value, { setZone: true })
|
|
42
|
+
// Calculate offset in hours (including minutes as decimal)
|
|
43
|
+
const offset = dt.offset / 60
|
|
44
|
+
// Find the matching time zone object
|
|
45
|
+
const matchedZone = dateTimeZoneFactory.getTimeZoneByOffset(offset)
|
|
46
|
+
// If found, set the zone on the DateTime object
|
|
47
|
+
if (matchedZone) {
|
|
48
|
+
// Format offset as UTC±HH:MM for non-integer offsets
|
|
49
|
+
const absOffset = Math.abs(matchedZone.value)
|
|
50
|
+
const hours = Math.floor(absOffset)
|
|
51
|
+
const minutes = Math.round((absOffset - hours) * 60)
|
|
52
|
+
const sign = matchedZone.value >= 0 ? '+' : '-'
|
|
53
|
+
const zoneString =
|
|
54
|
+
minutes === 0
|
|
55
|
+
? `UTC${sign}${hours}`
|
|
56
|
+
: `UTC${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`
|
|
57
|
+
$scope.parentMoment = dt.setZone(zoneString, { keepLocalTime: true })
|
|
58
|
+
$scope.timeZone = matchedZone
|
|
59
|
+
} else {
|
|
60
|
+
// Fallback: just use the parsed DateTime
|
|
61
|
+
$scope.parentMoment = dt
|
|
62
|
+
$scope.timeZone = null
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error(`Invalid value type ${typeof value} (${value})`)
|
|
66
|
+
}
|
|
41
67
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
$scope.timeZone = dateTimeZoneFactory.getTimeZone($scope.parentMoment)
|
|
68
|
+
$scope.timeMoment = DateTime.fromObject({ hour: $scope.parentMoment.hour, minute: $scope.parentMoment.minute, second: 0, millisecond: 0 })
|
|
69
|
+
$scope.dateMoment = DateTime.fromObject({ year: $scope.parentMoment.year, month: $scope.parentMoment.month, day: $scope.parentMoment.day })
|
|
45
70
|
}
|
|
46
71
|
|
|
47
72
|
function initParentMomentFromDatePicker(newDate) {
|
|
48
73
|
// when selecting a date from null or for the first time we need to
|
|
49
74
|
// initialize the parentMoment
|
|
50
|
-
$scope.parentMoment =
|
|
75
|
+
$scope.parentMoment = DateTime.now()
|
|
51
76
|
|
|
52
77
|
// the dateMoment is set by the datepicker, but we want to update the parent
|
|
53
78
|
// moment to have the same date
|
|
54
|
-
$scope.parentMoment.
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
$scope.parentMoment = $scope.parentMoment.set({
|
|
80
|
+
month: newDate.month,
|
|
81
|
+
year: newDate.year,
|
|
82
|
+
day: newDate.day
|
|
83
|
+
})
|
|
57
84
|
|
|
58
85
|
// we then init the timeMoment with a default of 12:00am
|
|
59
|
-
$scope.timeMoment =
|
|
86
|
+
$scope.timeMoment = DateTime.fromFormat('12:00 AM', 'hh:mm a')
|
|
60
87
|
|
|
61
|
-
// parent moment will have the now, but should also
|
|
62
|
-
$scope.parentMoment
|
|
63
|
-
|
|
88
|
+
// parent moment will have the now, but should also initially have 12:00am
|
|
89
|
+
$scope.parentMoment = $scope.parentMoment.set({
|
|
90
|
+
hour: $scope.timeMoment.hour,
|
|
91
|
+
minute: $scope.timeMoment.minute,
|
|
92
|
+
second: 0,
|
|
93
|
+
millisecond: 0,
|
|
94
|
+
})
|
|
64
95
|
|
|
65
|
-
// and init the time zone from the users's local time zone as we did in the initFromAPI
|
|
96
|
+
// and init the time zone from the users's local time zone as we did in the initFromAPI function
|
|
66
97
|
$scope.timeZone = dateTimeZoneFactory.getTimeZone($scope.parentMoment)
|
|
67
98
|
}
|
|
68
99
|
|
|
69
100
|
// Formatter runs when incoming values come from the model - this is
|
|
70
|
-
// where we initialize our
|
|
71
|
-
ngModelCtrl.$formatters.push(function(modelValue) {
|
|
101
|
+
// where we initialize our DateTime.
|
|
102
|
+
ngModelCtrl.$formatters.push(function (modelValue) {
|
|
72
103
|
|
|
73
104
|
if (modelValue) {
|
|
74
105
|
initParentMomentFromAPI(modelValue)
|
|
@@ -82,14 +113,14 @@ angular.module('app').directive('mflyDateTimeZonePicker', ['dateTimeZoneFactory'
|
|
|
82
113
|
return modelValue
|
|
83
114
|
})
|
|
84
115
|
|
|
85
|
-
ngModelCtrl.$parsers.push(function(modelValue) {
|
|
116
|
+
ngModelCtrl.$parsers.push(function (modelValue) {
|
|
86
117
|
return modelValue
|
|
87
118
|
})
|
|
88
119
|
|
|
89
120
|
function updateAPIFromMoment() {
|
|
90
121
|
|
|
91
122
|
if ($scope.parentMoment) {
|
|
92
|
-
ngModelCtrl.$setViewValue($scope.parentMoment.
|
|
123
|
+
ngModelCtrl.$setViewValue($scope.parentMoment.toISO())
|
|
93
124
|
}
|
|
94
125
|
else {
|
|
95
126
|
ngModelCtrl.$setViewValue(null)
|
|
@@ -97,15 +128,20 @@ angular.module('app').directive('mflyDateTimeZonePicker', ['dateTimeZoneFactory'
|
|
|
97
128
|
}
|
|
98
129
|
|
|
99
130
|
|
|
100
|
-
$scope.updateDate = function(newDate) {
|
|
101
|
-
// This is fired when the datepicker has updated the date portion of the
|
|
131
|
+
$scope.updateDate = function (newDate) {
|
|
132
|
+
// This is fired when the datepicker has updated the date portion of the DateTime
|
|
102
133
|
// Update the parentMoment with only the date change
|
|
103
134
|
if (newDate) {
|
|
135
|
+
// Update dateMoment to reflect the new date (needed for template visibility)
|
|
136
|
+
$scope.dateMoment = newDate
|
|
137
|
+
|
|
104
138
|
if ($scope.parentMoment) {
|
|
105
139
|
// if we have a parent moment update it
|
|
106
|
-
$scope.parentMoment.
|
|
107
|
-
|
|
108
|
-
|
|
140
|
+
$scope.parentMoment = $scope.parentMoment.set({
|
|
141
|
+
month: newDate.month,
|
|
142
|
+
year: newDate.year,
|
|
143
|
+
day: newDate.day
|
|
144
|
+
})
|
|
109
145
|
}
|
|
110
146
|
else {
|
|
111
147
|
// if we do not have a parent moment b/c no previous date existed
|
|
@@ -114,43 +150,50 @@ angular.module('app').directive('mflyDateTimeZonePicker', ['dateTimeZoneFactory'
|
|
|
114
150
|
}
|
|
115
151
|
else {
|
|
116
152
|
// we are clearing out a date
|
|
117
|
-
$scope.
|
|
153
|
+
$scope.dateMoment = null
|
|
154
|
+
$scope.parentMoment = null
|
|
118
155
|
}
|
|
119
156
|
|
|
120
|
-
// changing between DST could alter our UTC
|
|
157
|
+
// changing between DST could alter our UTC offset
|
|
121
158
|
// this adjustment happens in updateTimeZone which we can call here
|
|
122
|
-
|
|
159
|
+
if ($scope.timeZone) {
|
|
160
|
+
$scope.updateTimeZone($scope.timeZone.value)
|
|
161
|
+
}
|
|
123
162
|
}
|
|
124
163
|
|
|
125
164
|
|
|
126
|
-
$scope.updateTime = function() {
|
|
127
|
-
// This is fired when the timepicker has updated the time portion of the
|
|
165
|
+
$scope.updateTime = function () {
|
|
166
|
+
// This is fired when the timepicker has updated the time portion of the DateTime
|
|
128
167
|
// Update the parentMoment with only the time change
|
|
129
|
-
$scope.parentMoment
|
|
130
|
-
|
|
168
|
+
$scope.parentMoment = $scope.parentMoment.set({
|
|
169
|
+
hour: $scope.timeMoment.hour,
|
|
170
|
+
minute: $scope.timeMoment.minute,
|
|
171
|
+
second: 0,
|
|
172
|
+
millisecond: 0,
|
|
173
|
+
})
|
|
131
174
|
|
|
132
175
|
updateAPIFromMoment()
|
|
133
176
|
}
|
|
134
177
|
|
|
135
|
-
$scope.updateTimeZone = function(zoneOffset) {
|
|
178
|
+
$scope.updateTimeZone = function (zoneOffset) {
|
|
136
179
|
|
|
137
180
|
if ($scope.parentMoment !== '') {
|
|
138
181
|
|
|
139
|
-
// The zone
|
|
182
|
+
// The zone offset displays with a dst offset (see date-time-zone-factory for details)
|
|
140
183
|
// When we save back to the API we need to re-account for that offset
|
|
141
|
-
// Create a
|
|
142
|
-
const isDST =
|
|
184
|
+
// Create a DateTime to determine if we are dst
|
|
185
|
+
const isDST = DateTime.fromISO($scope.parentMoment.toISO()).isInDST
|
|
143
186
|
|
|
144
187
|
// adjust the zoneOffset passed from the UI if the date is dst
|
|
145
188
|
zoneOffset = (isDST) ? zoneOffset + 1 : zoneOffset
|
|
146
189
|
// update the zone/offset change
|
|
147
|
-
$scope.parentMoment.
|
|
190
|
+
$scope.parentMoment = $scope.parentMoment.setZone('UTC' + (zoneOffset >= 0 ? '+' : '') + zoneOffset, { keepLocalTime: true })
|
|
148
191
|
}
|
|
149
192
|
|
|
150
193
|
updateAPIFromMoment()
|
|
151
194
|
}
|
|
152
195
|
|
|
153
|
-
$scope.pickerOpened = function() {
|
|
196
|
+
$scope.pickerOpened = function () {
|
|
154
197
|
$scope.onOpen()
|
|
155
198
|
}
|
|
156
199
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import angular from 'angular'
|
|
2
|
-
import
|
|
2
|
+
import { DateTime } from 'luxon'
|
|
3
3
|
import Pikaday from 'pikaday'
|
|
4
4
|
import { recursivelySetPristine } from '../form-validation-utils/form-validation-utils'
|
|
5
5
|
import type { TranslateFactory } from '../translate/translate-factory'
|
|
@@ -37,7 +37,7 @@ angular.module('app').directive('mflyDatePicker', [
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// if a "small" format is required we need to set it here
|
|
40
|
-
const dateStringFormat = ($scope.format === 'short') ? '
|
|
40
|
+
const dateStringFormat = ($scope.format === 'short') ? 'd-MMM-yyyy' : 'd-MMMM-yyyy'
|
|
41
41
|
|
|
42
42
|
// The Pikaday component does some odd formatting at times
|
|
43
43
|
// This flag helps avoid this anomaly when it occurs
|
|
@@ -51,10 +51,9 @@ angular.module('app').directive('mflyDatePicker', [
|
|
|
51
51
|
|
|
52
52
|
// set up default options for the pikaday component
|
|
53
53
|
const pikadayOptions = {
|
|
54
|
-
field:
|
|
55
|
-
trigger: wrapperDiv[0],
|
|
54
|
+
field: wrapperDiv[0],
|
|
56
55
|
firstDay: 1,
|
|
57
|
-
format: dateStringFormat,
|
|
56
|
+
format: dateStringFormat.toUpperCase(), // Pikaday expects uppercase format
|
|
58
57
|
yearRange: 10,
|
|
59
58
|
setDefaultDate: true,
|
|
60
59
|
defaultDate: '',
|
|
@@ -71,21 +70,37 @@ angular.module('app').directive('mflyDatePicker', [
|
|
|
71
70
|
// Handler for when a date is 'selected' with the picker
|
|
72
71
|
// selection happens on enter, blur, and by using the popup calendars
|
|
73
72
|
onSelect() {
|
|
74
|
-
// update the bound date moment
|
|
75
|
-
|
|
73
|
+
// update the bound date moment - convert from JS Date to DateTime
|
|
74
|
+
const selectedDate = picker.getDate()
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
const updateDate = () => {
|
|
77
|
+
$scope.dateMoment = selectedDate ? DateTime.fromJSDate(selectedDate) : null
|
|
78
|
+
// fire a change in the parent directive for the api
|
|
79
|
+
$scope.onDateChange({ newDate: $scope.dateMoment })
|
|
80
|
+
|
|
81
|
+
// Set the form control as dirty and valid when date changes
|
|
82
|
+
$scope.form?.validation?.mflyDatepicker?.$setDirty()
|
|
83
|
+
$scope.form?.validation?.mflyDatepicker?.$setValidity('invalidDate', true)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Safely handle the digest cycle
|
|
87
|
+
if ($scope.$root.$$phase !== '$digest' && $scope.$root.$$phase !== '$apply') {
|
|
88
|
+
$scope.$apply(updateDate)
|
|
89
|
+
} else {
|
|
90
|
+
updateDate()
|
|
91
|
+
}
|
|
79
92
|
}
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
// Handle for the Pikaday component
|
|
83
96
|
const picker = new Pikaday(pikadayOptions)
|
|
84
97
|
|
|
85
|
-
$scope.$watch('dateMoment', function(newValue, oldValue) {
|
|
98
|
+
$scope.$watch('dateMoment', function(newValue: any, oldValue) {
|
|
86
99
|
|
|
87
100
|
if (newValue === oldValue) { // i.e., initializing
|
|
88
|
-
|
|
101
|
+
if ($scope.dateMoment) {
|
|
102
|
+
picker.setDate($scope.dateMoment.toJSDate())
|
|
103
|
+
}
|
|
89
104
|
recursivelySetPristine($scope.form.validation)
|
|
90
105
|
return
|
|
91
106
|
}
|
|
@@ -103,7 +118,9 @@ angular.module('app').directive('mflyDatePicker', [
|
|
|
103
118
|
|
|
104
119
|
// Otherwise, it may be a legit change. For example, if the model was
|
|
105
120
|
// programmatically changed from somewhere outside the component.
|
|
106
|
-
picker.
|
|
121
|
+
picker.setDate(newValue.toJSDate(), true) // true = do not trigger onSelect
|
|
122
|
+
// Also update the input value to match our format
|
|
123
|
+
$scope.dateInputValue.date = newValue.toFormat(dateStringFormat)
|
|
107
124
|
})
|
|
108
125
|
|
|
109
126
|
// watch necessary to style preceding add-on element (CSS has no prev sibling selector)
|
|
@@ -121,27 +138,55 @@ angular.module('app').directive('mflyDatePicker', [
|
|
|
121
138
|
|
|
122
139
|
$scope.setPikadayMoment = function() {
|
|
123
140
|
|
|
124
|
-
|
|
141
|
+
// Try parsing with any valid format, just like in validateDate
|
|
142
|
+
let tempDateTime
|
|
143
|
+
for (const format of dateTimeZoneFactory.validDateFormats) {
|
|
144
|
+
tempDateTime = DateTime.fromFormat($scope.dateInputValue.date, format)
|
|
145
|
+
if (tempDateTime.isValid) {
|
|
146
|
+
break
|
|
147
|
+
}
|
|
148
|
+
}
|
|
125
149
|
|
|
126
150
|
// The pikaday will oddly format 2 digit years to 0003
|
|
127
|
-
// The year is correct in the
|
|
128
|
-
// To prevent we will set the
|
|
129
|
-
if (!preventPikadayUpdate) {
|
|
130
|
-
|
|
151
|
+
// The year is correct in the dateTime, but you can see the odd string when formatted
|
|
152
|
+
// To prevent we will set the dateTime manually if the user is not backspacing/deleting
|
|
153
|
+
if (!preventPikadayUpdate && tempDateTime && tempDateTime.isValid) {
|
|
154
|
+
// Set the date without triggering onSelect to avoid circular updates
|
|
155
|
+
picker.setDate(tempDateTime.toJSDate(), true)
|
|
156
|
+
|
|
157
|
+
// Manually update the dateMoment to trigger reformatting
|
|
158
|
+
const updateDateTime = () => {
|
|
159
|
+
$scope.dateMoment = tempDateTime
|
|
160
|
+
$scope.onDateChange({ newDate: tempDateTime })
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Safely handle the digest cycle
|
|
164
|
+
if ($scope.$root.$$phase !== '$digest' && $scope.$root.$$phase !== '$apply') {
|
|
165
|
+
$scope.$apply(updateDateTime)
|
|
166
|
+
} else {
|
|
167
|
+
updateDateTime()
|
|
168
|
+
}
|
|
131
169
|
} else {
|
|
132
170
|
preventPikadayUpdate = false
|
|
133
171
|
}
|
|
134
172
|
}
|
|
135
173
|
|
|
136
|
-
// called
|
|
174
|
+
// called every time the text input is changed manually
|
|
137
175
|
$scope.validateDate = function() {
|
|
138
176
|
// pikaday interrupts the normal binding - manually update scope
|
|
139
177
|
$scope.dateInputValue.date = angular.element(inputElement[0]).val()
|
|
140
178
|
|
|
141
179
|
let isValid = true
|
|
142
180
|
if ($scope.dateInputValue.date && $scope.dateInputValue.date.length > 0) {
|
|
143
|
-
// attempt to create a date
|
|
144
|
-
isValid =
|
|
181
|
+
// attempt to create a date from value using any valid format
|
|
182
|
+
isValid = false
|
|
183
|
+
for (const format of dateTimeZoneFactory.validDateFormats) {
|
|
184
|
+
const parsed = DateTime.fromFormat($scope.dateInputValue.date, format)
|
|
185
|
+
if (parsed.isValid) {
|
|
186
|
+
isValid = true
|
|
187
|
+
break
|
|
188
|
+
}
|
|
189
|
+
}
|
|
145
190
|
|
|
146
191
|
if (isValid) {
|
|
147
192
|
$scope.setPikadayMoment()
|
|
@@ -166,6 +211,17 @@ angular.module('app').directive('mflyDatePicker', [
|
|
|
166
211
|
}
|
|
167
212
|
}
|
|
168
213
|
|
|
214
|
+
$scope.onBlur = function() {
|
|
215
|
+
// Hide the Pikaday calendar popup
|
|
216
|
+
picker.hide()
|
|
217
|
+
|
|
218
|
+
// Update focus state
|
|
219
|
+
$scope.focusAddOn = false
|
|
220
|
+
|
|
221
|
+
// Validate the date
|
|
222
|
+
$scope.validateDate()
|
|
223
|
+
}
|
|
224
|
+
|
|
169
225
|
$scope.requiredText = translateFactory.instant('JSUI.REQUIRED')
|
|
170
226
|
$scope.invalidDateText = translateFactory.instant('JSUI.INVALID_DATE')
|
|
171
227
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import angular from 'angular'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import
|
|
3
|
+
import { DateTime } from 'luxon'
|
|
4
4
|
|
|
5
5
|
// This filter takes a datetime string with UTC offset, like `2015-09-30T00:00:00-08:00`
|
|
6
6
|
// and converts it to a short format with time zone code displayed, like `12:00 AM AKST`.
|
|
@@ -13,7 +13,7 @@ angular.module('app').filter('formatDate', function formatDate() {
|
|
|
13
13
|
return ''
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const formattedDateTime =
|
|
16
|
+
const formattedDateTime = DateTime.fromISO(date, { setZone: true }).toFormat('M/dd/yy')
|
|
17
17
|
|
|
18
18
|
return formattedDateTime
|
|
19
19
|
}
|
|
@@ -28,9 +28,9 @@ angular.module('app').filter('formatTimeWithTimeZone', ['dateTimeZoneFactory', f
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Parse zone preserves the string date's offset --ignoring offset in locale)
|
|
31
|
-
const dateTimeZone =
|
|
31
|
+
const dateTimeZone = DateTime.fromISO(date, { setZone: true })
|
|
32
32
|
|
|
33
|
-
const formattedTime = dateTimeZone.
|
|
33
|
+
const formattedTime = dateTimeZone.toFormat('h:mm a')
|
|
34
34
|
|
|
35
35
|
// NOTE: getTimeZone expects a momentDate
|
|
36
36
|
const formattedZone = dateTimeZoneFactory.getTimeZone(dateTimeZone).display
|
|
@@ -48,9 +48,9 @@ angular.module('app').filter('formatDateTimeWithTimeZone', ['dateTimeZoneFactory
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// Parse zone preserves the string date's offset --ignoring offset in locale)
|
|
51
|
-
const dateTimeZone =
|
|
51
|
+
const dateTimeZone = DateTime.fromISO(date, { setZone: true })
|
|
52
52
|
|
|
53
|
-
const formattedDateTime =
|
|
53
|
+
const formattedDateTime = DateTime.fromISO(date, { setZone: true }).toFormat('M/dd/yy h:mm a')
|
|
54
54
|
|
|
55
55
|
// NOTE: getTimeZone expects a momentDate
|
|
56
56
|
const formattedZone = dateTimeZoneFactory.getTimeZone(dateTimeZone).display
|