-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_helper.js
160 lines (134 loc) · 6.56 KB
/
date_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
(function() {
var DateHelper, DateTimeSelector, InstanceTag, TagHelper;
DateTimeSelector = require('./datetime_selector');
TagHelper = require('tag-helper');
InstanceTag = require('instance-tag');
DateHelper = (function() {
function DateHelper() {}
DateHelper.prototype.date_select = function(object_name, method, options, html_options) {
var tag;
if (options == null) options = {};
if (html_options == null) html_options = {};
delete options.object;
tag = new InstanceTag(object_name, method, this, options);
return tag.to_date_select_tag(options, html_options);
};
DateHelper.prototype.time_select = function(object_name, method, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
delete options.object;
return (new InstanceTag(object_name, method, this, options)).to_time_select_tag(options, html_options);
};
DateHelper.prototype.datetime_select = function(object_name, method, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
delete options.object;
return (new InstanceTag(object_name, method, this, options)).to_datetime_select_tag(options, html_options);
};
DateHelper.prototype.select_datetime = function(datetime, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
if ((arguments.length === 0) && ((datetime === null) || (datetime === void 0))) {
datetime = new Date();
}
return (new DateTimeSelector(datetime, options, html_options)).select_datetime();
};
DateHelper.prototype.select_date = function(date, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
if ((arguments.length === 0) && ((date === null) || (date === void 0))) {
date = new Date();
}
return (new DateTimeSelector(date, options, html_options)).select_date();
};
DateHelper.prototype.select_time = function(datetime, options, html_options) {
if (datetime == null) datetime = Time.current;
if (options == null) options = {};
if (html_options == null) html_options = {};
return (new DateTimeSelector(datetime, options, html_options)).select_time();
};
DateHelper.prototype.select_second = function(datetime, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return (new DateTimeSelector(datetime, options, html_options)).select_second();
};
DateHelper.prototype.select_minute = function(datetime, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return (new DateTimeSelector(datetime, options, html_options)).select_minute();
};
DateHelper.prototype.select_hour = function(datetime, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return (new DateTimeSelector(datetime, options, html_options)).select_hour();
};
DateHelper.prototype.select_day = function(date, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return (new DateTimeSelector(date, options, html_options)).select_day();
};
DateHelper.prototype.select_month = function(date, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return (new DateTimeSelector(date, options, html_options)).select_month();
};
DateHelper.prototype.select_year = function(date, options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return (new DateTimeSelector(date, options, html_options)).select_year();
};
return DateHelper;
})();
InstanceTag.prototype.to_date_select_tag = function(options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return this.datetime_selector(options, html_options).select_date().html_safe().valueOf();
};
InstanceTag.prototype.to_time_select_tag = function(options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return this.datetime_selector(options, html_options).select_time().html_safe().valueOf();
};
InstanceTag.prototype.to_datetime_select_tag = function(options, html_options) {
if (options == null) options = {};
if (html_options == null) html_options = {};
return this.datetime_selector(options, html_options).select_datetime().html_safe().valueOf();
};
InstanceTag.prototype.datetime_selector = function(options, html_options) {
var datetime, _base, _name;
datetime = (typeof (_base = this.object)[_name = this.method_name] === "function" ? _base[_name]() : void 0) || this.default_datetime(options);
this.auto_index || (this.auto_index = null);
options = Object.clone(options);
options.field_name = this.method_name;
options.include_position = true;
options.prefix || (options.prefix = this.object_name);
if (this.auto_index && !(options.index != null)) {
options.index = this.auto_index;
}
return new DateTimeSelector(datetime, options, html_options);
};
InstanceTag.prototype.default_datetime = function(options) {
var default_options, key, time, _i, _len, _ref;
if (!(options.include_blank || options.prompt)) {
if (!options["default"]) {
return new Date();
} else if (options["default"] instanceof Date) {
return options["default"];
} else {
default_options = Object.clone(options["default"]);
default_options.min || (default_options.min = default_options.minute);
default_options.sec || (default_options.sec = default_options.second);
time = new Date();
_ref = ['month', 'hours', 'minutes', 'seconds'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i];
default_options[key] || (default_options[key] = time["get" + (key.capitalize())]());
}
default_options.fullYear || (default_options.fullYear = time["getFullYear"]());
default_options.day || (default_options.day = time["getDate"]());
return new Date(default_options.fullYear, default_options.month, default_options.day, default_options.hours, default_options.minutes, default_options.seconds);
}
}
};
module.exports = new DateHelper();
}).call(this);