|
129 | 129 | var startDecade = (parseInt(selectedDate.year() / 10, 10) * 10)
|
130 | 130 | var startDate = moment.utc(startOfDecade(milliseconds)).subtract(1, 'year').startOf('year')
|
131 | 131 |
|
132 |
| - var activeYear = formatValue(ngModelController.$modelValue, 'YYYY') |
| 132 | + var yearFormat = 'YYYY' |
| 133 | + var activeFormat = formatValue(ngModelController.$modelValue, yearFormat) |
| 134 | + var currentFormat = moment().format(yearFormat) |
133 | 135 |
|
134 | 136 | var result = {
|
135 | 137 | 'currentView': 'year',
|
|
146 | 148 | for (var i = 0; i < 12; i += 1) {
|
147 | 149 | var yearMoment = moment.utc(startDate).add(i, 'years')
|
148 | 150 | var dateValue = {
|
149 |
| - 'utcDateValue': yearMoment.valueOf(), |
150 |
| - 'display': yearMoment.format('YYYY'), |
151 |
| - 'past': yearMoment.year() < startDecade, |
| 151 | + 'active': yearMoment.format(yearFormat) === activeFormat, |
| 152 | + 'current': yearMoment.format(yearFormat) === currentFormat, |
| 153 | + 'display': yearMoment.format(yearFormat), |
152 | 154 | 'future': yearMoment.year() > startDecade + 9,
|
153 |
| - 'active': yearMoment.format('YYYY') === activeYear |
| 155 | + 'past': yearMoment.year() < startDecade, |
| 156 | + 'utcDateValue': yearMoment.valueOf() |
154 | 157 | }
|
155 | 158 |
|
156 | 159 | result.dates.push(new DateObject(dateValue))
|
|
162 | 165 | function monthModelFactory (milliseconds) {
|
163 | 166 | var startDate = moment.utc(milliseconds).startOf('year')
|
164 | 167 | var previousViewDate = startOfDecade(milliseconds)
|
165 |
| - var activeDate = formatValue(ngModelController.$modelValue, 'YYYY-MMM') |
| 168 | + |
| 169 | + var monthFormat = 'YYYY-MMM' |
| 170 | + var activeFormat = formatValue(ngModelController.$modelValue, monthFormat) |
| 171 | + var currentFormat = moment().format(monthFormat) |
166 | 172 |
|
167 | 173 | var result = {
|
168 | 174 | 'previousView': 'year',
|
|
180 | 186 | for (var i = 0; i < 12; i += 1) {
|
181 | 187 | var monthMoment = moment.utc(startDate).add(i, 'months')
|
182 | 188 | var dateValue = {
|
183 |
| - 'utcDateValue': monthMoment.valueOf(), |
| 189 | + 'active': monthMoment.format(monthFormat) === activeFormat, |
| 190 | + 'current': monthMoment.format(monthFormat) === currentFormat, |
184 | 191 | 'display': monthMoment.format('MMM'),
|
185 |
| - 'active': monthMoment.format('YYYY-MMM') === activeDate |
| 192 | + 'utcDateValue': monthMoment.valueOf() |
186 | 193 | }
|
187 | 194 |
|
188 | 195 | result.dates.push(new DateObject(dateValue))
|
|
199 | 206 |
|
200 | 207 | var startDate = moment.utc(startOfMonth).subtract(Math.abs(startOfMonth.weekday()), 'days')
|
201 | 208 |
|
202 |
| - var activeDate = formatValue(ngModelController.$modelValue, 'YYYY-MMM-DD') |
| 209 | + var dayFormat = 'YYYY-MMM-DD' |
| 210 | + var activeFormat = formatValue(ngModelController.$modelValue, dayFormat) |
| 211 | + var currentFormat = moment().format(dayFormat) |
203 | 212 |
|
204 | 213 | var result = {
|
205 | 214 | 'previousView': 'month',
|
|
222 | 231 | for (var i = 0; i < 6; i += 1) {
|
223 | 232 | var week = {dates: []}
|
224 | 233 | for (var j = 0; j < 7; j += 1) {
|
225 |
| - var monthMoment = moment.utc(startDate).add((i * 7) + j, 'days') |
| 234 | + var dayMoment = moment.utc(startDate).add((i * 7) + j, 'days') |
226 | 235 | var dateValue = {
|
227 |
| - 'utcDateValue': monthMoment.valueOf(), |
228 |
| - 'display': monthMoment.format('D'), |
229 |
| - 'active': monthMoment.format('YYYY-MMM-DD') === activeDate, |
230 |
| - 'past': monthMoment.isBefore(startOfMonth), |
231 |
| - 'future': monthMoment.isAfter(endOfMonth) |
| 236 | + 'active': dayMoment.format(dayFormat) === activeFormat, |
| 237 | + 'current': dayMoment.format(dayFormat) === currentFormat, |
| 238 | + 'display': dayMoment.format('D'), |
| 239 | + 'future': dayMoment.isAfter(endOfMonth), |
| 240 | + 'past': dayMoment.isBefore(startOfMonth), |
| 241 | + 'utcDateValue': dayMoment.valueOf() |
232 | 242 | }
|
233 | 243 | week.dates.push(new DateObject(dateValue))
|
234 | 244 | }
|
|
242 | 252 | var selectedDate = moment.utc(milliseconds).startOf('day')
|
243 | 253 | var previousViewDate = moment.utc(selectedDate).startOf('month')
|
244 | 254 |
|
245 |
| - var activeFormat = formatValue(ngModelController.$modelValue, 'YYYY-MM-DD H') |
| 255 | + var hourFormat = 'YYYY-MM-DD H' |
| 256 | + var activeFormat = formatValue(ngModelController.$modelValue, hourFormat) |
| 257 | + var currentFormat = moment().format(hourFormat) |
246 | 258 |
|
247 | 259 | var result = {
|
248 | 260 | 'previousView': 'day',
|
|
260 | 272 | for (var i = 0; i < 24; i += 1) {
|
261 | 273 | var hourMoment = moment.utc(selectedDate).add(i, 'hours')
|
262 | 274 | var dateValue = {
|
263 |
| - 'utcDateValue': hourMoment.valueOf(), |
| 275 | + 'active': hourMoment.format(hourFormat) === activeFormat, |
| 276 | + 'current': hourMoment.format(hourFormat) === currentFormat, |
264 | 277 | 'display': hourMoment.format('LT'),
|
265 |
| - 'active': hourMoment.format('YYYY-MM-DD H') === activeFormat |
| 278 | + 'utcDateValue': hourMoment.valueOf() |
266 | 279 | }
|
267 | 280 |
|
268 | 281 | result.dates.push(new DateObject(dateValue))
|
|
274 | 287 | function minuteModelFactory (milliseconds) {
|
275 | 288 | var selectedDate = moment.utc(milliseconds).startOf('hour')
|
276 | 289 | var previousViewDate = moment.utc(selectedDate).startOf('day')
|
277 |
| - var activeFormat = formatValue(ngModelController.$modelValue, 'YYYY-MM-DD H:mm') |
| 290 | + |
| 291 | + var minuteFormat = 'YYYY-MM-DD H:mm' |
| 292 | + var activeFormat = formatValue(ngModelController.$modelValue, minuteFormat) |
| 293 | + var currentFormat = moment().format(minuteFormat) |
278 | 294 |
|
279 | 295 | var result = {
|
280 | 296 | 'previousView': 'hour',
|
|
294 | 310 | for (var i = 0; i < limit; i += 1) {
|
295 | 311 | var hourMoment = moment.utc(selectedDate).add(i * configuration.minuteStep, 'minute')
|
296 | 312 | var dateValue = {
|
297 |
| - 'utcDateValue': hourMoment.valueOf(), |
| 313 | + 'active': hourMoment.format(minuteFormat) === activeFormat, |
| 314 | + 'current': hourMoment.format(minuteFormat) === currentFormat, |
298 | 315 | 'display': hourMoment.format('LT'),
|
299 |
| - 'active': hourMoment.format('YYYY-MM-DD H:mm') === activeFormat |
| 316 | + 'utcDateValue': hourMoment.valueOf() |
300 | 317 | }
|
301 | 318 |
|
302 | 319 | result.dates.push(new DateObject(dateValue))
|
|
413 | 430 | return this.utcDateValue + localOffset
|
414 | 431 | }
|
415 | 432 |
|
416 |
| - var validProperties = ['utcDateValue', 'display', 'active', 'selectable', 'past', 'future'] |
| 433 | + var validProperties = ['active', 'current', 'display', 'future', 'past', 'selectable', 'utcDateValue'] |
417 | 434 |
|
418 | 435 | var constructorObject = arguments[0]
|
419 | 436 |
|
|
422 | 439 | }).forEach(function (key) {
|
423 | 440 | this[key] = constructorObject[key]
|
424 | 441 | }, this)
|
425 |
| - |
426 |
| - this.isToday = moment().utc().local().format('YYYY-MM-DD') === moment.utc(this.utcDateValue).format('YYYY-MM-DD') |
427 | 442 | }
|
428 | 443 |
|
429 | 444 | return directiveDefinition
|
|
0 commit comments