Skip to content

Commit

Permalink
Added Format as a parameter in callbacks
Browse files Browse the repository at this point in the history
Added Format as a parameter in `parseDateTimeString` and
`formatDateTimeString` callbacks to let it support different formats.
Previously, with this function parsing or formatting of only one format
was possible. Now based on format different code can be written for
parsing or formatting the date.

```
parseDateTimeString: function(sDateTime, sMode, sFormat, oInputElement)
{
}
```

```
formatDateTimeString: function(oDate, sMode, sFormat, oInputElement) {
}
```
Added exmaple in which date format of date string in input field is
different from the date format of date string to be displayed on
DateTimePicker, as requested in #125

Added exmaple for using different date formats for storing date in the
database and displaying on DateTimePicker, as requested in #122
  • Loading branch information
nehakadam committed Nov 5, 2016
1 parent 593a382 commit 3db1e48
Show file tree
Hide file tree
Showing 51 changed files with 280 additions and 73 deletions.
2 changes: 1 addition & 1 deletion DateTimePicker.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"keywords": ["date", "time", "datetime", "plugin", "picker", "DatePicker", "TimePicker", "DateTimePicker", "Responsive", "Flat", "Mobile", "jquery"],

"version": "0.1.36",
"version": "0.1.37",

"author": {
"name": "Curious Solutions",
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"input"
],

"version": "0.1.36",
"version": "0.1.37",

"homepage": "http://curioussolutions.github.io/DateTimePicker/",

Expand Down
2 changes: 1 addition & 1 deletion demo/BasicExamples-CustomEvent.htm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script type="text/javascript" src="../src/DateTimePicker-ltie9.js"></script>
<![endif]-->

<style>
<style type="text/css">

p
{
Expand Down
121 changes: 121 additions & 0 deletions demo/BasicExamples-CustomInputValue-Issue125.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!DOCTYPE html>

<html>

<head>

<title>Custom Input Value</title>

<link rel="stylesheet" type="text/css" href="../src/DateTimePicker.css" />

<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="../src/DateTimePicker.js"></script>

<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="../src/DateTimePicker-ltie9.css" />
<script type="text/javascript" src="../src/DateTimePicker-ltie9.js"></script>
<![endif]-->

<style>

p
{
margin-left: 20px;
}

input
{
width: 200px;
padding: 10px;
margin-left: 20px;
margin-bottom: 20px;
}

.btn
{
background: #FFFFFF;
color: #A3A3CC;

border: 2px solid #A3A3CC;
border-radius: 5px;

padding: 10px 20px;
margin: 20px;

font-size: 12px;

cursor: pointer;
}

</style>

</head>

<body>

<p>Date : </p>
<input id="input-date" type="text" data-field="date" data-format="dd-MM-yyyy" value="2016-07-05" readonly>

<div id="dateBox"></div>

<script type="text/javascript">

$(document).ready(function()
{
var oDTP1;

$("#dateBox").DateTimePicker(
{
addEventHandlers: function()
{
oDTP = this;

oDTP.settings.maxDate = oDTP.getDateTimeStringInFormat("date", "dd-MM-yyyy", new Date());
},

parseDateTimeString: function(sDateTime, sMode, sFormat, oInputElement)
{
oDTP1 = this;

console.log(sDateTime + " " + sMode);
var dThisDate = new Date(),
iArrDateTimeComps, sRegex;

if($.cf._isValid(sDateTime))
{
// "2016-10-26"
sRegex = /(\d{1,4})(-)(\d{1,2})(-)(\d{1,2})/;

iArrDateTimeComps = sDateTime.match(sRegex);


dThisDate = new Date(
parseInt(iArrDateTimeComps[1]),
parseInt(iArrDateTimeComps[3]) - 1,
parseInt(iArrDateTimeComps[5]),
0, 0, 0, 0
);
}

return dThisDate;
},

formatDateTimeString: function(oDate, sMode, sFormat, oInputElement)
{
oDTP1 = this;

console.log("formatDateTimeString " + sFormat);
console.log(oDate);
if(sFormat === "yyyy-MM-dd")
return oDate.yyyy + "-" + oDate.MM + "-" + oDate.dd;
else if(sFormat === "dd-MM-yyyy")
return oDate.dd + "-" + oDate.MM + "-" + oDate.yyyy;
}
});
});

</script>

</body>

</html>
4 changes: 2 additions & 2 deletions demo/BasicExamples-CustomInputValue.htm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

parentElement: ".cont-date",

parseDateTimeString: function(sDateTime, sMode, oInputElement)
parseDateTimeString: function(sDateTime, sMode, sFormat, oInputElement)
{
oDTP1 = this;

Expand All @@ -123,7 +123,7 @@
return dThisDate;
},

formatDateTimeString: function(oDate, sMode, oInputElement)
formatDateTimeString: function(oDate, sMode, sFormat, oInputElement)
{
oDTP1 = this;

Expand Down
86 changes: 86 additions & 0 deletions demo/FormatConversion.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!DOCTYPE html>

<html>

<head>

<title>Basic Examples - Set DateTime In Input Field</title>

<link rel="stylesheet" type="text/css" href="../src/DateTimePicker.css" />

<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="../src/DateTimePicker.js"></script>

<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="../src/DateTimePicker-ltie9.css" />
<script type="text/javascript" src="../src/DateTimePicker-ltie9.js"></script>
<![endif]-->

<style type="text/css">

p
{
margin-left: 20px;
}

input
{
width: 200px;
padding: 10px;
margin-left: 20px;
margin-bottom: 20px;
}

</style>

</head>

<body>

<p>Date : </p>
<input type="text" data-field="date" data-format="dd-MM-yyyy" readonly>

<div id="dtBox"></div>

<script type="text/javascript">

var inputDateString = "2016-10-22", outputDateString, dDateTime;

$(document).ready(function()
{
$("#dtBox").DateTimePicker(
{

addEventHandlers: function()
{
oDTP = this;
var inputDateStringComp = inputDateString.split("-");

// Set Date
oDTP.settings.defaultDate = new Date(parseInt(inputDateStringComp[0]), parseInt(inputDateStringComp[1]) - 1, parseInt(inputDateStringComp[2]), 0, 0, 0, 0);
dDateTime = new Date(oDTP.settings.defaultDate);

oDTP.setDateTimeStringInInputField($("input"), oDTP.settings.defaultDate);
},

settingValueOfElement: function(sElemValue, dElemValue, oElem)
{
oDTP = this;

if(oDTP.settings.mode === "date")
{
dDateTime = new Date(dElemValue.getFullYear(), dElemValue.getMonth(), dElemValue.getDate(), 0, 0, 0, 0);

outputDateString = oDTP.getDateTimeStringInFormat("date", "yyyy-MM-dd");
}

console.log(dDateTime + " -- " + outputDateString);
}
});
});

</script>

</body>

</html>
2 changes: 1 addition & 1 deletion dist/DateTimePicker-ltie9.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
jQuery DateTimePicker - Responsive flat design jQuery DateTime Picker plugin for Web & Mobile
Version 0.1.36
Version 0.1.37
Copyright (c)2016 Curious Solutions LLP and Neha Kadam
http://curioussolutions.github.io/DateTimePicker
https://github.com/CuriousSolutions/DateTimePicker
Expand Down
2 changes: 1 addition & 1 deletion dist/DateTimePicker-ltie9.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
jQuery DateTimePicker - Responsive flat design jQuery DateTime Picker plugin for Web & Mobile
Version 0.1.36
Version 0.1.37
Copyright (c)2016 Curious Solutions LLP and Neha Kadam
http://curioussolutions.github.io/DateTimePicker
https://github.com/CuriousSolutions/DateTimePicker
Expand Down
2 changes: 1 addition & 1 deletion dist/DateTimePicker-ltie9.min.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
jQuery DateTimePicker - Responsive flat design jQuery DateTime Picker plugin for Web & Mobile
Version 0.1.36
Version 0.1.37
Copyright (c)2016 Curious Solutions LLP and Neha Kadam
http://curioussolutions.github.io/DateTimePicker
https://github.com/CuriousSolutions/DateTimePicker
Expand Down
2 changes: 1 addition & 1 deletion dist/DateTimePicker-ltie9.min.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
jQuery DateTimePicker - Responsive flat design jQuery DateTime Picker plugin for Web & Mobile
Version 0.1.36
Version 0.1.37
Copyright (c)2016 Curious Solutions LLP and Neha Kadam
http://curioussolutions.github.io/DateTimePicker
https://github.com/CuriousSolutions/DateTimePicker
Expand Down
2 changes: 1 addition & 1 deletion dist/DateTimePicker.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------------
jQuery DateTimePicker - Responsive flat design jQuery DateTime Picker plugin for Web & Mobile
Version 0.1.36
Version 0.1.37
Copyright (c)2016 Curious Solutions LLP and Neha Kadam
http://curioussolutions.github.io/DateTimePicker
https://github.com/CuriousSolutions/DateTimePicker
Expand Down
Loading

0 comments on commit 3db1e48

Please sign in to comment.