A datetime/week picker widget that can be used on a web page. This project is the modification and improvement of another project at
https://github.com/eternicode/bootstrap-datepicker/
version 1.4.0 which is developed by Andrew Rowls + contributors.
All documentation in http://bootstrap-datepicker.readthedocs.org/en/stable/ should apply to this project. Here will be explained the modifications/extensions made in this project. There are three major features added to this project:
-
This project uses
JsSimpleDateFormat
library which is developed by me. This library has wider formatting pattern including time that will be used by time picker. The formatting pattern used by this library is similar to that used by Java SimpleDateFormat class and also similar to .NET date time string format. If you use Java or ASP.NET as the server-side code, it's a benefit if we use the same format pattern between client and server.To use
JsSimpleDateFormat
, you must includeJsSimpleDateFormat.js
script beforebootstrap-datepicker.js
, like below:<script src="./js/JsSimpleDateFormat.min.js"></script> <script src="./js/bootstrap-datepicker.min.js"></script>
If you omitJsSimpleDateFormat.js
, datepicker will use the internal format pattern as described at
http://bootstrap-datepicker.readthedocs.org/en/stable/options.html#format -
Week picker is to select a whole week, instead of a single day. The
weekstart
option determines the first day of the week. To use week picker, setweekPicker
option totrue
. By default, it'sfalse
. The week will be displayed as[first date of week][separator][last date of week]
. The default separator is hyphen (-). To use different seperator, setweekPicker
option to an object whoseseparator
property, such as:weekPicker: { separator: ' upto ' }
Besideseparator
property, the object may have two methods:formatWeek
andgetWeekStart
.formatWeek
is to format the week more freely. It may ignoreseparator
property.getWeekStart
is to parse the string formatted byformatWeek
and returns the first date of the week. For example, considerweekstart
option is set to sunday, we can use the following code:weekPicker: { formatWeek: function(startWeekDate, options, $datepicker) { var df = new JsSimpleDateFormat("'Week-'W of MMM yyyy"); return df.format(startWeekDate); }, getWeekStart: function(weekString, options, $datepicker) { var df = new JsSimpleDateFormat("'Week-'W of MMM yyyy"); df.isLenient = true; return df.parse(weekString); } }
-
Beside date, this widget can set time. Some coditions in the use of time:
- It must use
JsSimpleDateFormat
. weekPicker
andmultidate
option must be set tofalse
.- Time picker will appear if
format pattern
includes
H
,k
,K
,h
,m
ors
. These are the format pattern for time. - If
s
is specified in format string then hour, minute and second picker will appear. Ifm
is specified but nos
then only hour and minute will appear. If nom
ands
is in format string then only hour will appear. The AM/PM button will appear if you useK
orh
in format string. - If time picker appears then there is
nowBtn
option that can be used. It's liketodayBtn
except it will also set the time to the current time. The possible values fornowBtn
are the same as those fortodayBtn
option.
- It must use
-
If either side (start or end date) is blank (null), it means infinite for that side. Range visualization is also available for month/year view. There is a new option which applies to range,
disableIfExceedRange
. If this option is set totrue
(by default it'sfalse
) then the start date cannot be set more than the end date and the end date cannot be set less than the start date. If this option isfalse
then if the start date is set more than the end date, it will move the end date to the same date as the start date.