Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 21777cf22f
Fetching contributors…

Cannot retrieve contributors at this time

executable file 254 lines (243 sloc) 17.474 kb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JavaScript unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="assets/jsunittest.js" type="text/javascript"></script>
<script src="jquery-1.4.min.js" type="text/javascript"></script>
<script src="jquery.dateFormat-1.0.js" type="text/javascript"></script>
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
</head>
<body>
<div id="content">
<div id="header">
<h1>JavaScript unit test file</h1>
</div>
<!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
<div id="testlog"></div>
<!-- Put sample/test html here -->
<div id="sample">
</div>
</div>
<script type="text/javascript"><!--
// <![CDATA[
new Test.Unit.Runner({
setup: function() {
},
teardown: function() {
},
testISO8601Format : function() { with(this) {
var jsonDate = "2009-12-18T10:54:50Z";
assertEqual('18/12/2009', $.format.date(jsonDate, 'dd/MM/yyyy'));
assertEqual('Dec/2009', $.format.date(jsonDate, 'MMM/yyyy'));
assertEqual('12', $.format.date(jsonDate, 'MM'));
assertEqual('18', $.format.date(jsonDate, 'dd'));
assertEqual('2009', $.format.date(jsonDate, 'yyyy'));
assertEqual('12', $.format.date(jsonDate, 'MM'));
assertEqual('10:54:50', $.format.date(jsonDate, 'hh:mm:ss'));
assertEqual('10', $.format.date(jsonDate, 'hh'));
assertEqual('54', $.format.date(jsonDate, 'mm'));
assertEqual('50', $.format.date(jsonDate, 'ss'));
assertEqual('18/12/2009 10:54:50 AM', $.format.date(jsonDate, 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z18/b12/c2009 x10:e54:f50', $.format.date(jsonDate, 'zdd/bMM/cyyyy xhh:emm:fss'));
var jsonDate = "2009-12-18T13:54:50Z";
assertEqual('18/12/2009 01:54:50', $.format.date(jsonDate, 'dd/MM/yyyy hh:mm:ss'));
assertEqual('18/12/2009 13:54:50', $.format.date(jsonDate, 'dd/MM/yyyy HH:mm:ss'));
assertEqual('18/12/2009 01:54:50 PM', $.format.date(jsonDate, 'dd/MM/yyyy hh:mm:ss a'));
}},
testJavaUtilDateFormat : function() { with(this) {
/* Java java.util.Date output */
assertEqual('18/12/2009', $.format.date('2009-12-18 10:54:50.546', 'dd/MM/yyyy'));
assertEqual('Dec/2009', $.format.date('2009-12-18 10:54:50.546', 'MMM/yyyy'));
assertEqual('12', $.format.date('2009-12-18 10:54:50.546', 'MM'));
assertEqual('05', $.format.date('2009-12-5 10:54:50.546', 'dd'));
assertEqual('2009', $.format.date('2009-12-18 10:54:50.546', 'yyyy'));
assertEqual('12', $.format.date('2009-12-18 10:54:50.546', 'MM'));
assertEqual('10:54:50', $.format.date('2009-12-18 10:54:50.546', 'hh:mm:ss'));
assertEqual('10', $.format.date('2009-12-18 10:54:50.546', 'hh'));
assertEqual('54', $.format.date('2009-12-18 10:54:50.546', 'mm'));
assertEqual('50', $.format.date('2009-12-18 10:54:50.546', 'ss'));
assertEqual('546', $.format.date('2009-12-18 10:54:50.546', 'SSS'));
assertEqual('18/12/2009 01:54:50', $.format.date('2009-12-18 13:54:50.546', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('18/12/2009 14:54:50', $.format.date('2009-12-18 14:54:50.546', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('18/12/2009 10:54:50 AM', $.format.date('2009-12-18 10:54:50.546', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('18/12/2009 01:54:50 PM', $.format.date('2009-12-18 13:54:50.546', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z18/b12/c2009 x10:e54:f50', $.format.date('2009-12-18 10:54:50.546', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('2010', $.format.date(new Date(1274370756526), 'yyyy'));
assertEqual('Friday', $.format.date('2009-12-18 10:54:50.546', 'ddd'));
}},
testFormatDateType2 : function() { with(this) {
/* ??? Wed Jan 13 10:43:41 CET 2010 */
assertEqual('01/01/2010', $.format.date('Wed Jan 1 10:43:41 CET 2010', 'dd/MM/yyyy'));
assertEqual('Jan/2010', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'MMM/yyyy'));
assertEqual('01', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'MM'));
assertEqual('05', $.format.date('Wed Jan 5 10:43:41 CET 2010', 'dd'));
assertEqual('2010', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'yyyy'));
assertEqual('01', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'MM'));
assertEqual('10:43:41', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'hh:mm:ss'));
assertEqual('10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'hh'));
assertEqual('43', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'mm'));
assertEqual('41', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'ss'));
assertEqual('13/01/2010 01:43:41', $.format.date('Wed Jan 13 13:43:41 CET 2010', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('13/01/2010 14:43:41', $.format.date('Wed Jan 13 14:43:41 CET 2010', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('13/01/2010 10:43:41 AM', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('13/01/2010 05:43:41 PM', $.format.date('Wed Jan 13 17:43:41 CET 2010', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z13/b01/c2010 x10:e43:f41', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Wednesday', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'ddd'));
}},
testJAXBFormat : function() { with(this) {
/* Java JAXB java.util.Date output */
assertEqual('19/10/2010', $.format.date('2010-10-19T11:40:33.527+02:00', 'dd/MM/yyyy'));
assertEqual('Oct/2010', $.format.date('2010-10-19T11:40:33.527+02:00', 'MMM/yyyy'));
assertEqual('10', $.format.date('2010-10-19T11:40:33.527+02:00', 'MM'));
assertEqual('05', $.format.date('2010-10-05T11:40:33.527+02:00', 'dd'));
assertEqual('2010', $.format.date('2010-10-19T11:40:33.527+02:00', 'yyyy'));
assertEqual('19', $.format.date('2010-10-19T11:40:33.527+02:00', 'dd'));
assertEqual('11:40:33', $.format.date('2010-10-19T11:40:33.527+02:00', 'hh:mm:ss'));
assertEqual('11', $.format.date('2010-10-19T11:40:33.527+02:00', 'hh'));
assertEqual('40', $.format.date('2010-10-19T11:40:33.527+02:00', 'mm'));
assertEqual('33', $.format.date('2010-10-19T11:40:33.527+02:00', 'ss'));
assertEqual('19/10/2010 01:43:41', $.format.date('2010-10-19T13:43:41.527+02:00', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('19/10/2010 14:43:41', $.format.date('2010-10-19T14:43:41.527+02:000', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('19/10/2010 10:43:41 AM', $.format.date('2010-10-19T10:43:41.527+02:00', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('19/10/2010 05:43:41 PM', $.format.date('2010-10-19T17:43:41.527+02:00', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z19/b10/c2010 x11:e40:f33', $.format.date('2010-10-19T11:40:33.527+02:00', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Tuesday', $.format.date('2010-10-19T11:40:33.527+02:00', 'ddd'));
}},
testeJavaScriptDateFormat: function() { with(this) {
/* JavaScript Date output */
assertEqual('19/10/2010', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'dd/MM/yyyy'));
assertEqual('Oct/2010', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'MMM/yyyy'));
assertEqual('10', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'MM'));
assertEqual('05', $.format.date(new Date('10/5/2010 11:40:33').toString(), 'dd'));
assertEqual('2010', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'yyyy'));
assertEqual('19', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'dd'));
assertEqual('11:40:33', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'hh:mm:ss'));
assertEqual('11', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'hh'));
assertEqual('40', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'mm'));
assertEqual('33', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'ss'));
assertEqual('19/10/2010 01:43:41', $.format.date(new Date('10/19/2010 13:43:41').toString(), 'dd/MM/yyyy hh:mm:ss'));
assertEqual('19/10/2010 14:43:41', $.format.date(new Date('10/19/2010 14:43:41').toString(), 'dd/MM/yyyy HH:mm:ss'));
assertEqual('19/10/2010 10:43:41 AM', $.format.date(new Date('10/19/2010 10:43:41').toString(), 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('19/10/2010 05:43:41 PM', $.format.date(new Date('10/19/2010 17:43:41').toString(), 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z19/b10/c2010 x11:e40:f33', $.format.date(new Date('10/19/2010 11:40:33').toString(), 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Tuesday', $.format.date(new Date('10/19/2010 10:43:41').toString(), 'ddd'));
}},
testFormatDateType5: function() { with(this) {
assertEqual('08/04/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy'));
assertEqual('Apr/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'MMM/yyyy'));
assertEqual('04', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'MM'));
assertEqual('08', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd'));
assertEqual('2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'yyyy'));
assertEqual('19', $.format.date('Fri Apr 19 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd'));
assertEqual('01:02:03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'hh:mm:ss'));
assertEqual('01', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'hh'));
assertEqual('02', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'mm'));
assertEqual('03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'ss'));
assertEqual('08/04/2011 01:02:03', $.format.date('Fri Apr 08 2011 13:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('08/04/2011 14:02:03', $.format.date('Fri Apr 08 2011 14:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('08/04/2011 01:02:03 AM', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('08/04/2011 07:02:03 PM', $.format.date('Fri Apr 08 2011 19:02:03 GMT+0800 (China Standard Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z08/b04/c2011 x01:e02:f03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0800 (China Standard Time)', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Friday', $.format.date('Fri Apr 08 2011 13:02:03 GMT+0800 (China Standard Time)', 'ddd'));
}},
testFormatDateType6: function() { with(this) {
assertEqual('08/04/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy'));
assertEqual('Apr/2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'MMM/yyyy'));
assertEqual('04', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'MM'));
assertEqual('08', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd'));
assertEqual('2011', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'yyyy'));
assertEqual('19', $.format.date('Fri Apr 19 2011 01:02:03 GMT+0800 (China Standard Time)', 'dd'));
assertEqual('01:02:03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'hh:mm:ss'));
assertEqual('01', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'hh'));
assertEqual('02', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'mm'));
assertEqual('03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'ss'));
assertEqual('08/04/2011 01:02:03', $.format.date('Fri Apr 08 2011 13:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy hh:mm:ss'));
assertEqual('08/04/2011 14:02:03', $.format.date('Fri Apr 08 2011 14:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy HH:mm:ss'));
assertEqual('08/04/2011 01:02:03 AM', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('08/04/2011 07:02:03 PM', $.format.date('Fri Apr 08 2011 19:02:03 GMT+0200 (W. Europe Daylight Time)', 'dd/MM/yyyy hh:mm:ss a'));
assertEqual('z08/b04/c2011 x01:e02:f03', $.format.date('Fri Apr 08 2011 01:02:03 GMT+0200 (W. Europe Daylight Time)', 'zdd/bMM/cyyyy xhh:emm:fss'));
assertEqual('Friday', $.format.date('Fri Apr 08 2011 14:02:03 GMT+0200 (W. Europe Daylight Time)', 'ddd'));
}},
testFormatDateType7: function() { with(this) {
/* Reference: http://pablocantero.com/blog/2010/09/04/jquery-plugin-javascript-for-java-util-date-tostring-format/#comment-259520318 */
assertEqual('19/04/2009', $.format.date('2009-04-19T16:11:05-02:00', 'dd/MM/yyyy'));
assertEqual('Apr/2009', $.format.date('2009-04-19T16:11:05-02:00', 'MMM/yyyy'));
}},
testFormatDateType8: function() { with(this) {
/* Reference: http://pablocantero.com/blog/2010/09/04/jquery-plugin-javascript-for-java-util-date-tostring-format/#comment-178490699 */
assertEqual('05:45PM', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'hh:mma'));
}},
testDayInWeek: function() { with(this) {
assertEqual('Monday', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'ddd'));
}},
testMonthInYear: function() { with(this) {
assertEqual('Mar', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'MMM'));
assertEqual('March', $.format.date('Mon Mar 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'MMMM'));
}},
testLongMonth: function() { with(this) {
assertEqual('February', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'MMMM'));
}},
testShortYear: function() { with(this) {
assertEqual(11, $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'yy'));
assertEqual(12, $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'yy'));
assertEqual('13.01.10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy'));
}},
testShortHour: function() { with(this) {
assertEqual('5', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('5', $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('13.01.10 10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy h'));
assertEqual('6', $.format.date('Wed Jan 25 06:23:38 PST 2012', 'h'));
assertEqual('06', $.format.date('Wed Jan 25 06:23:38 PST 2012', 'hh'));
assertEqual('5', $.format.date('Mon Feb 28 2011 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('5', $.format.date('Mon Feb 28 20112 17:45:00 GMT-0400 (Eastern Daylight Time)', 'h'));
assertEqual('13.01.10 10', $.format.date('Wed Jan 13 10:43:41 CET 2010', 'dd.MM.yy h'));
}},
testIssue19: function() { with(this) {
assertEqual('Sep 29, 2011', $.format.date("2011-09-29 14:50:49", "MMM dd, yyyy"));
}},
testIssue17: function() { with(this) {
assertEqual('2011-04-25 09:04', $.format.date("2011-04-25T09:04:14.7270000", "yyyy-MM-dd HH:mm"));
}},
testShortDay: function() { with(this) {
assertEqual('January 9, 2012', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'MMMM d, yyyy'));
assertEqual('January 09, 2012', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'MMMM dd, yyyy'));
}},
testJapanese: function() { with(this) {
assertEqual('2012年01月09日', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'yyyy年MM月dd日'));
}},
testIssue24: function() { with(this) {
assertEqual('-', $.format.date('Wed Jan 09 06:23:38 PST 2012', '-'));
assertEqual('9-', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'd-'));
assertEqual('9/', $.format.date('Wed Jan 09 06:23:38 PST 2012', 'd/'));
}},
testPullRequest: function() { with(this) {
// https://github.com/phstc/jquery-dateFormat/pull/22
assertEqual('07/02/2012', $.format.date('2012-02-07CET00:00:00', 'dd/MM/yyyy'));
assertEqual('Feb/2012', $.format.date('2012-02-07CET00:00:00', 'MMM/yyyy'));
assertEqual('02', $.format.date('2012-02-07CET00:00:00', 'MM'));
assertEqual('07', $.format.date('2012-02-07CET00:00:00', 'dd'));
assertEqual('2012', $.format.date('2012-02-07CET00:00:00', 'yyyy'));
}},
testUnixTimeStamp: function() { with(this) {
// https://github.com/phstc/jquery-dateFormat/pull/22
var testDate = new Date("Jan 2, 2000 01:02:03");
assertEqual("01", $.format.date(testDate.getTime(), 'MM'));
assertEqual("2", $.format.date(testDate.getTime(), 'd'));
assertEqual("2000", $.format.date(testDate.getTime(), 'yyyy'));
assertEqual("01", $.format.date(testDate.getTime(), 'HH'));
assertEqual("02", $.format.date(testDate.getTime(), 'mm'));
assertEqual("03", $.format.date(testDate.getTime(), 'ss'));
}},
testeShortMonthNoPrependedZero: function() { with(this) {
var testDate = new Date("Jan 2, 2000 01:02:03");
assertEqual('2', $.format.date('Wed Feb 09 06:23:38 PST 2012', 'M'));
assertEqual("1", $.format.date(testDate.getTime(), 'M'));
assertEqual('5', $.format.date('2012-05-07CET00:00:00', 'M'));
}},
});
// ]]>
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.