dev ldap fixes (#3914)
[openemr.git] / library / formatting_DateToYYYYMMDD_js.js.php
blobcce4f8a3f8d20ce1f3c76f2181876a4684257c5c
1 <?php
3 /**
4 * javascripts function to allow date internationalization
5 * and converts date back to YYYY-MM-DD and YYYY-MM-DD HH:MM:SS (SS is optional)
6 * formats
8 * @package OpenEMR
9 * @link https://www.open-emr.org
10 * @author Shachar Zilbershlag <shaharzi@matrix.co.il>
11 * @author Amiel Elboim <amielel@matrix.co.il>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
14 * @copyright Copyright (c) 2016 Amiel Elboim <amielel@matrix.co.il>
15 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
16 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
21 function DateToYYYYMMDD_js(value){
22 var value = value.replace(/\//g,'-');
23 var parts = value.split('-');
24 var date_display_format = <?php echo js_escape((empty($GLOBALS['date_display_format']) ? 0 : $GLOBALS['date_display_format'])) ?>;
26 if (date_display_format == 1) // mm/dd/yyyy, note year is added below
27 value = parts[2] + '-' + parts[0] + '-' + parts[1];
28 else if (date_display_format == 2) // dd/mm/yyyy, note year is added below
29 value = parts[2] + '-' + parts[1] + '-' + parts[0];
31 return value;
34 function TimeToHHMMSS_js(value){
35 //For now, just return the Value, since input fields are not formatting time.
36 // This can be upgraded if decided to format input time fields.
37 return value.trim();
40 function DateToYYYYMMDDHHMMSS_js(value){
41 if (typeof value === 'undefined') {
42 return undefined;
44 var parts = value.split(' ');
46 var datePart = DateToYYYYMMDD_js(parts[0]);
47 var timePart = TimeToHHMMSS_js(parts[1]);
49 var value = datePart + ' ' + timePart;
51 return value.trim();