Skip to content

Commit 2317572

Browse files
committed
Refactor time routines into TimeBase mixin.
Remove “datePackage” property since it’s based on global variables (ex: dojox.date.hebrew). Instead subclass must set dateClassObj, dateModule, dateLocaleModule, and _calendar.
1 parent d60c748 commit 2317572

File tree

6 files changed

+284
-510
lines changed

6 files changed

+284
-510
lines changed

CalendarBase.js

+4-109
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
define([
22
"dcl/dcl",
33
"dojo/_base/lang",
4-
"dojo/date",
5-
"dojo/date/locale",
64
"dojo/dom-class",
75
"dojo/dom-style",
86
"dojo/dom-construct",
97
"dojo/dom-geometry",
108
"./metrics",
119
"./StoreBase",
12-
"./time",
10+
"./TimeBase",
1311
"dojo/i18n!./nls/buttons"
1412
], function (
1513
dcl,
1614
lang,
17-
date,
18-
locale,
1915
domClass,
2016
domStyle,
2117
domConstruct,
2218
domGeometry,
2319
metrics,
2420
StoreBase,
25-
timeUtil,
21+
TimeBase,
2622
_nls
2723
) {
2824
/*=====
@@ -139,19 +135,13 @@ define([
139135
};
140136
=====*/
141137

142-
return dcl(StoreBase, {
143-
138+
return dcl([StoreBase, TimeBase], {
144139
// summary:
145140
// This class defines a generic calendar widget that manages several views to display event in time.
146141
// It needs to be subclassed, specifically defining `_computeCurrentView()`.
147142

148143
baseClass: "d-calendar",
149144

150-
// datePackage: Object
151-
// JavaScript namespace to find Calendar routines.
152-
// Uses Gregorian Calendar routines at dojo.date by default.
153-
datePackage: date,
154-
155145
// startDate: Date
156146
// The start date of the displayed time interval.
157147
startDate: null,
@@ -195,13 +185,6 @@ define([
195185
// The DOM node that will contains the views.
196186
viewContainer: null,
197187

198-
// firstDayOfWeek: Integer
199-
// (Optional) The first day of week override. By default the first day of week is determined
200-
// for the current locale (extracted from the CLDR).
201-
// 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday.
202-
// Special value -1 (default value) means to use the locale dependent value.
203-
firstDayOfWeek: -1,
204-
205188
// formatItemTime: Function?
206189
// Optional function to format the time of day of the item renderers.
207190
// The function takes the date, the render data object, the view and
@@ -262,7 +245,7 @@ define([
262245
forwardProperties: [
263246
"source", "query", "queryOptions", "startTimeAttr", "endTimeAttr", "summaryAttr", "allDayAttr",
264247
"subColumnAttr", "decodeDate", "encodeDate", "itemToRenderItem", "renderItemToItem", "cssClassFunc",
265-
"datePackage",
248+
"dateClassObj", "dateModule", "dateLocaleModule", "_calendar",
266249
"endDate", "date", "minDate", "maxDate", "dateInterval", "dateIntervalSteps",
267250
"firstDayOfWeek",
268251
"formatItemTime",
@@ -279,20 +262,9 @@ define([
279262
// The currentViewChange event can be used to react on a view change.
280263
currentView: null,
281264

282-
_calendar: "gregorian",
283-
284265
// Make nls strings available to template
285266
_nls: _nls,
286267

287-
createdCallback: function (/*Object*/args) {
288-
args = args || {};
289-
this._calendar = args.datePackage ? args.datePackage.substr(args.datePackage.lastIndexOf(".") + 1) :
290-
this._calendar;
291-
this.dateModule = args.datePackage ? lang.getObject(args.datePackage, false) : date;
292-
this.dateClassObj = this.dateModule.Date || Date;
293-
this.dateLocaleModule = args.datePackage ? lang.getObject(args.datePackage + ".locale", false) : locale;
294-
},
295-
296268
postRender: function () {
297269
this.viewContainer.on("delite-add-child", function (evt) {
298270
this._onViewAdded(evt.child);
@@ -550,7 +522,6 @@ define([
550522
view.owner = this;
551523
view.buttonContainer = this.buttonContainer;
552524
view._calendar = this._calendar;
553-
view.datePackage = this.datePackage;
554525
view.dateModule = this.dateModule;
555526
view.dateClassObj = this.dateClassObj;
556527
view.dateLocaleModule = this.dateLocaleModule;
@@ -681,82 +652,6 @@ define([
681652
}
682653
},
683654

684-
685-
/////////////////////////////////////////////////////
686-
//
687-
// Time utilities
688-
//
689-
////////////////////////////////////////////////////
690-
691-
floorToDay: function (date, reuse) {
692-
// summary:
693-
// Floors the specified date to the start of day.
694-
// date: Date
695-
// The date to floor.
696-
// reuse: Boolean
697-
// Whether use the specified instance or create a new one. Default is false.
698-
// returns: Date
699-
700-
return timeUtil.floorToDay(date, reuse, this.dateClassObj);
701-
},
702-
703-
floorToWeek: function (d) {
704-
// summary:
705-
// Floors the specified date to the beginning of week.
706-
// date: Date
707-
// Date to floor.
708-
709-
return timeUtil.floorToWeek(d, this.dateClassObj, this.dateModule, this.firstDayOfWeek, this.locale);
710-
},
711-
712-
newDate: function (obj) {
713-
// summary:
714-
// Creates a new Date object.
715-
// obj: Object
716-
// This object can have several values:
717-
// - the time in milliseconds since gregorian epoch.
718-
// - a Date instance
719-
// returns: Date
720-
721-
return timeUtil.newDate(obj, this.dateClassObj);
722-
},
723-
724-
isToday: function (date) {
725-
// summary:
726-
// Returns whether the specified date is in the current day.
727-
// date: Date
728-
// The date to test.
729-
// returns: Boolean
730-
731-
return timeUtil.isToday(date, this.dateClassObj);
732-
},
733-
734-
isStartOfDay: function (d) {
735-
// summary:
736-
// Tests if the specified date represents the starts of day.
737-
// d:Date
738-
// The date to test.
739-
// returns: Boolean
740-
741-
return timeUtil.isStartOfDay(d, this.dateClassObj, this.dateModule);
742-
},
743-
744-
floorDate: function (date, unit, steps, reuse) {
745-
// summary:
746-
// floors the date to the unit.
747-
// date: Date
748-
// The date/time to floor.
749-
// unit: String
750-
// The unit. Valid values are "minute", "hour", "day".
751-
// steps: Integer
752-
// For "day" only 1 is valid.
753-
// reuse: Boolean
754-
// Whether use the specified instance or create a new one. Default is false.
755-
// returns: Date
756-
757-
return timeUtil.floor(date, unit, steps, reuse, this.classFuncObj);
758-
},
759-
760655
nextRange: function () {
761656
this._navigate(1);
762657
},

StoreBase.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ define([
5050
return function (storeItem) {
5151
// Override to use decodeDate() method.
5252
var ri = sup.apply(this, arguments);
53-
ri.startTime = (this.decodeDate || this.newDate)(ri.startTime);
54-
ri.endTime = (this.decodeDate || this.newDate)(ri.endTime);
53+
ri.startTime = this.decodeDate ? this.decodeDate(ri.startTime) : this.newDate(ri.startTime);
54+
ri.endTime = this.decodeDate ? this.decodeDate(ri.endTime) : this.newDate(ri.endTime);
5555

5656
// Also, some of the code depends on renderItem._item pointing back to the original store item.
5757
ri._item = storeItem;

0 commit comments

Comments
 (0)