Skip to content

Commit 10598d1

Browse files
committed
Removed curly brackets for title format strings
1 parent 23be819 commit 10598d1

File tree

7 files changed

+31
-39
lines changed

7 files changed

+31
-39
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ Also DatePickerX provides global `DatePickerX` object with following methods:
5252
* `todayButtonLabel` - today button label. Default: `'Today'`
5353
* `clearButton` - if `true` clear button should be enabled. Date picker value will be cleared by clicking this button. Default: `true`
5454
* `clearButtonLabel` - clear button label. Default: `'Clear'`
55-
* `titleFormatDay` - Title format for day value items. All literals from the `format` property can be used. Each literal should be wrapped in curly brackets. Default: `'{MM} {dd}, {yyyy}'`
56-
* `titleFormatMonth` - Title format for month value items. All literals from the `format` property can be used. Each literal should be wrapped in curly brackets. Default: `'{MM} {yyyy}'`
57-
* `titleFormatYear` - Title format for year value items. All literals from the `format` property can be used. Each literal should be wrapped in curly brackets. Default: `'{yyyy}'`
55+
* `titleFormatDay` - Title format for day value items. All literals from the `format` property can be used. Default: `'MM dd, yyyy'`
56+
* `titleFormatMonth` - Title format for month value items. All literals from the `format` property can be used. Default: `'MM yyyy'`
57+
* `titleFormatYear` - Title format for year value items. All literals from the `format` property can be used. Default: `'yyyy'`

dist/css/DatePickerX.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Alexander Krupko <[email protected]>
88
* @copyright 2016 Alexander Krupko
99
* @license MIT
10-
* @version 1.0.5
10+
* @version 1.0.7
1111
*/
1212

1313
.date-picker-x-container {

dist/css/DatePickerX.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/DatePickerX.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Alexander Krupko <[email protected]>
88
* @copyright 2016 Alexander Krupko
99
* @license MIT
10-
* @version 1.0.5
10+
* @version 1.0.7
1111
*/
1212

1313
!function()
@@ -26,9 +26,9 @@
2626
todayButtonLabel : 'Today',
2727
clearButton : true,
2828
clearButtonLabel : 'Clear',
29-
titleFormatDay : '{MM} {dd}, {yyyy}',
30-
titleFormatMonth : '{MM} {yyyy}',
31-
titleFormatYear : '{yyyy}'
29+
titleFormatDay : 'MM dd, yyyy',
30+
titleFormatMonth : 'MM yyyy',
31+
titleFormatYear : 'yyyy'
3232
},
3333
openedDPX = null;
3434

@@ -155,9 +155,8 @@
155155
* MM - full month name
156156
* yy - 2-digits year number
157157
* yyyy - 4-digits year number
158-
* @param {Boolean} [useBrackets=false] If true, literals should be wrapped to curly brackets
159158
*/
160-
function getFormatedDate(dt, format, useBrackets)
159+
function getFormatedDate(dt, format)
161160
{
162161
var items = {
163162
d : dt.getDate(),
@@ -177,10 +176,9 @@
177176
items.M = options.shortMonthLabels[items.M];
178177
items.MM = options.singleMonthLabels[items.MM];
179178

180-
var regexp = useBrackets ? /\{([dmM]{1,2}|D|yyyy|yy)\}/g : /([dmM]{1,2}|D|yyyy|yy)/g;
181-
return format.replace(regexp, function(match, literal)
179+
return format.replace(/([dmM]{1,2}|D|yyyy|yy)/g, function(match)
182180
{
183-
return typeof items[literal] !== 'undefined' ? items[literal] : match;
181+
return typeof items[match] !== 'undefined' ? items[match] : match;
184182
});
185183
}
186184

@@ -315,25 +313,23 @@
315313

316314
// set title
317315
elements.title.innerHTML = mode
318-
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true)
316+
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear)
319317
: (zeroYear + ' - ' + (zeroYear + 9));
320318
elements.title.dpxValue = dt.getTime();
321-
elements.title.title = mode === 2
322-
? getFormatedDate(dt, options.titleFormatYear, true)
323-
: (zeroYear + ' - ' + (zeroYear + 9));
319+
elements.title.title = mode === 2 ? getFormatedDate(dt, options.titleFormatYear) : (zeroYear + ' - ' + (zeroYear + 9));
324320

325321
// prev and next arrows
326322
elements.prevTitle.classList[dt.getTime() <= dtMin ? 'add' : 'remove']('dpx-disabled');
327323
mode === 2 ? dt.setMonth(setMonth - 1) : dt.setFullYear(mode ? setYear - 1 : zeroYear - 10);
328324
elements.prevTitle.title = mode
329-
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true)
325+
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear)
330326
: ((zeroYear - 10) + ' - ' + (zeroYear - 1));
331327
elements.prevTitle.dpxValue = dt.getTime();
332328

333329
mode === 2 ? dt.setMonth(dt.getMonth() + 2) : dt.setFullYear(mode ? setYear + 1 : zeroYear + 20);
334330
elements.nextTitle.classList[dt.getTime() > dtMax ? 'add' : 'remove']('dpx-disabled');
335331
elements.nextTitle.title = mode
336-
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true)
332+
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear)
337333
: ((zeroYear + 10) + ' - ' + (zeroYear + 19));
338334
elements.nextTitle.dpxValue = dt.getTime();
339335

@@ -381,7 +377,7 @@
381377
i = mode === 2 ? 42 : 16;
382378
for (; i--; dt[setter](dt[getter]() + 1)) {
383379
var classes = ['dpx-item'],
384-
title = getFormatedDate(dt, [options.titleFormatYear, options.titleFormatMonth, options.titleFormatDay][mode], true);
380+
title = getFormatedDate(dt, [options.titleFormatYear, options.titleFormatMonth, options.titleFormatDay][mode]);
385381

386382
(mode ? (mode === 2 ? dt.getMonth() !== setMonth : dt.getFullYear() !== setYear) : (dt.getFullYear() < zeroYear || dt.getFullYear() > zeroYear + 9)) && classes.push('dpx-out');
387383
mode === 2 && (dt.getDay() === 6 || dt.getDay() === 0) && classes.push('dpx-weekend');

dist/js/DatePickerX.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "datepickerx",
33
"title": "DatePickerX",
44
"description": "Cool light visual date picker on pure JavaScript",
5-
"version": "1.0.6",
5+
"version": "1.0.7",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/AlexKrupko/DatePickerX"

src/js/DatePickerX.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
todayButtonLabel : 'Today',
1515
clearButton : true,
1616
clearButtonLabel : 'Clear',
17-
titleFormatDay : '{MM} {dd}, {yyyy}',
18-
titleFormatMonth : '{MM} {yyyy}',
19-
titleFormatYear : '{yyyy}'
17+
titleFormatDay : 'MM dd, yyyy',
18+
titleFormatMonth : 'MM yyyy',
19+
titleFormatYear : 'yyyy'
2020
},
2121
openedDPX = null;
2222

@@ -143,9 +143,8 @@
143143
* MM - full month name
144144
* yy - 2-digits year number
145145
* yyyy - 4-digits year number
146-
* @param {Boolean} [useBrackets=false] If true, literals should be wrapped to curly brackets
147146
*/
148-
function getFormatedDate(dt, format, useBrackets)
147+
function getFormatedDate(dt, format)
149148
{
150149
var items = {
151150
d : dt.getDate(),
@@ -165,10 +164,9 @@
165164
items.M = options.shortMonthLabels[items.M];
166165
items.MM = options.singleMonthLabels[items.MM];
167166

168-
var regexp = useBrackets ? /\{([dmM]{1,2}|D|yyyy|yy)\}/g : /([dmM]{1,2}|D|yyyy|yy)/g;
169-
return format.replace(regexp, function(match, literal)
167+
return format.replace(/([dmM]{1,2}|D|yyyy|yy)/g, function(match)
170168
{
171-
return typeof items[literal] !== 'undefined' ? items[literal] : match;
169+
return typeof items[match] !== 'undefined' ? items[match] : match;
172170
});
173171
}
174172

@@ -303,25 +301,23 @@
303301

304302
// set title
305303
elements.title.innerHTML = mode
306-
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true)
304+
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear)
307305
: (zeroYear + ' - ' + (zeroYear + 9));
308306
elements.title.dpxValue = dt.getTime();
309-
elements.title.title = mode === 2
310-
? getFormatedDate(dt, options.titleFormatYear, true)
311-
: (zeroYear + ' - ' + (zeroYear + 9));
307+
elements.title.title = mode === 2 ? getFormatedDate(dt, options.titleFormatYear) : (zeroYear + ' - ' + (zeroYear + 9));
312308

313309
// prev and next arrows
314310
elements.prevTitle.classList[dt.getTime() <= dtMin ? 'add' : 'remove']('dpx-disabled');
315311
mode === 2 ? dt.setMonth(setMonth - 1) : dt.setFullYear(mode ? setYear - 1 : zeroYear - 10);
316312
elements.prevTitle.title = mode
317-
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true)
313+
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear)
318314
: ((zeroYear - 10) + ' - ' + (zeroYear - 1));
319315
elements.prevTitle.dpxValue = dt.getTime();
320316

321317
mode === 2 ? dt.setMonth(dt.getMonth() + 2) : dt.setFullYear(mode ? setYear + 1 : zeroYear + 20);
322318
elements.nextTitle.classList[dt.getTime() > dtMax ? 'add' : 'remove']('dpx-disabled');
323319
elements.nextTitle.title = mode
324-
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear, true)
320+
? getFormatedDate(dt, mode === 2 ? options.titleFormatMonth : options.titleFormatYear)
325321
: ((zeroYear + 10) + ' - ' + (zeroYear + 19));
326322
elements.nextTitle.dpxValue = dt.getTime();
327323

@@ -369,7 +365,7 @@
369365
i = mode === 2 ? 42 : 16;
370366
for (; i--; dt[setter](dt[getter]() + 1)) {
371367
var classes = ['dpx-item'],
372-
title = getFormatedDate(dt, [options.titleFormatYear, options.titleFormatMonth, options.titleFormatDay][mode], true);
368+
title = getFormatedDate(dt, [options.titleFormatYear, options.titleFormatMonth, options.titleFormatDay][mode]);
373369

374370
(mode ? (mode === 2 ? dt.getMonth() !== setMonth : dt.getFullYear() !== setYear) : (dt.getFullYear() < zeroYear || dt.getFullYear() > zeroYear + 9)) && classes.push('dpx-out');
375371
mode === 2 && (dt.getDay() === 6 || dt.getDay() === 0) && classes.push('dpx-weekend');

0 commit comments

Comments
 (0)