UNPKG

dojox

Version:

Dojo eXtensions, a rollup of many useful sub-projects and varying states of maturity – from very stable and robust, to alpha and experimental. See individual projects contain README files for details.

185 lines (156 loc) 5.57 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Date Conversions for Persian Widget</title> <style type="text/css"> @import "../../../dojo/resources/dojo.css"; @import "../../../dijit/tests/css/dijitTests.css"; </style> <!-- required: the default dijit theme: --> <link id="themeStyles" rel="stylesheet" href="../../../dijit/themes/tundra/tundra.css"> <!-- required: dojo.js --> <script type="text/javascript" src="../../../dojo/dojo.js" djConfig=" isDebug: true, parseOnLoad: true, extraLocale: ['en-us', 'fa-ir']"></script> <script> dojo.require("dijit/form/Form"); dojo.require("dojo/date"); dojo.require("dojo/date/locale"); dojo.require("dojox/date/persian"); dojo.require("dojox/date/persian/locale"); dojo.require("dijit/form/DateTextBox"); dojo.require("dojo/parser"); /** * @param actualFormat -- current format * @param requiredformat-- converted Format * @param source -- Source control * @param destination -- Destination control * @return */ function convertPersianToGregorianDate(actualFormat, requiredformat, source, destination) { var value = dijit.byId(source).attr('DisplayedValue'); var options = { datePattern : actualFormat, selector : 'date' }; var date = dojox.date.persian.locale.parse(value, options); date = date.toGregorian(); options.datePattern = requiredformat; var convertedDate = dojo.date.locale.format(date, options); dojo.byId(destination).value = convertedDate; } /** * @param actualFormat -- current format * @param requiredformat-- converted Format * @param source -- Source control * @param destination -- Destination control * @return */ function convertGregorianToPersianDate(actualFormat, requiredformat, source, destination) { var value = dijit.byId(source).attr('DisplayedValue'); var options = { datePattern : actualFormat, selector : 'date' }; var date = dojo.date.locale.parse(value, options); date = new dojox.date.persian.Date(new Date(date)); options.datePattern = requiredformat; var convertedDate = dojox.date.persian.locale.format(date, options); dojo.byId(destination).value = convertedDate; } </script> </head> <body class=" tundra "> <h1 class="testTitle">Test DateTextBoxNew Persian and Gregorian Widget:</h1> <form id="form1" dojoType='dijit.form.Form' action="" name="Persian" method=""> <div class="dojoTitlePaneLabel"><label for="q1"> Persian Calendar </label> <span class="noticeMessage">DateTextBox class, datePackage = "dojox.date.persian"</span></div> <table> <tr> <td><label id="lpdat1"> Persian Date :</label></td> <td><input type="combo" id="pDate1" name="dob" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'yyyy/MM/dd'}" lang="fa" datePackage="dojox.date.persian" onchange="convertPersianToGregorianDate('yyyy/MM/dd','yyyy/MM/dd','pDate1','gDate1')" value="2007-12-25" /></td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td><label id="lgdat1"> Gregorian Date(yyyy/MM/dd) :</label></td> <td><input id="gDate1" size="34" disabled value="not fired yet!" autocomplete="off"></td> <tr rows="3"></tr> </tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr> <td><label id="lgdat2">Gregorian Date :</label></td> <td><input type="combo" id="gDate2" name="dob" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'yyyy/MM/dd'}" onchange="convertGregorianToPersianDate('yyyy/MM/dd','yyyy/MM/dd','gDate2','pDate2')" value="2007-12-25" /></td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td><label id="lpdat2"> Persian Date (yyyy/MM/dd) :</label></td> <td><input id="pDate2" size="34" disabled value="not fired yet!" autocomplete="off"></td> </tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr> <td><label id="lgdat3">Persian Date :</label></td> <td><input type="combo" id="gDate3" name="dob" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'yyyy/MMM/dd'}" onchange="convertGregorianToPersianDate('yyyy/MMM/dd','yyyy/MMM/dd','gDate3','pDate3')" value="2007-12-25" /></td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td><label id="lpdat3"> Gregorian Date (yyyy/MMM/dd):</label></td> <td><input id="pDate3" size="34" disabled value="not fired yet!" autocomplete="off"></td> </tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr> <td><label id="lgdat4"> Persian Date :</label></td> <td><input type="combo" id="gDate4" name="dob" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'yyyy/MMM/dd'}" datePackage="dojox.date.persian" onchange="convertPersianToGregorianDate('yyyy/MMM/dd','yyyy/MMM/dd','gDate4','pDate4')" value="2007-12-25" /></td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td><label id="lpdat4"> Gregorian Date(yyyy/MMM/dd) </label></td> <td><input id="pDate4" size="34" disabled value="not fired yet!" autocomplete="off"></td> </tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr> <td><label id="lgdat5">Gregorian Date :</label></td> <td><input type="combo" id="gDate5" name="dob" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'yyyy/MMM/dd'}" datePackage="dojox.date.persian" onchange="convertPersianToGregorianDate('yyyy/MMM/dd','dd/MM/yyyy','gDate5','pDate5')" value="2007-12-25" /></td> <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td><label id="lpdat4"> Persian Date (dd/MM/yyyy):</label></td> <td><input id="pDate5" size="34" disabled value="not fired yet!" autocomplete="off"></td> </tr> </table> </form> </body> </html>