[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 module('Formats', { 2 setup: function(){ 3 this.input = $('<input type="text">').appendTo('#qunit-fixture'); 4 this.date = new Date(2012, 2, 15, 0, 0, 0, 0); // March 15, 2012 5 }, 6 teardown: function(){ 7 this.input.data('datepicker').picker.remove(); 8 } 9 }); 10 11 test('d: Day of month, no leading zero.', function(){ 12 this.input 13 .val('2012-03-05') 14 .datepicker({format: 'yyyy-mm-d'}) 15 .datepicker('setValue'); 16 equal(this.input.val().split('-')[2], '5'); 17 }); 18 19 test('dd: Day of month, leading zero.', function(){ 20 this.input 21 .val('2012-03-5') 22 .datepicker({format: 'yyyy-mm-dd'}) 23 .datepicker('setValue'); 24 equal(this.input.val().split('-')[2], '05'); 25 }); 26 27 test('m: Month, no leading zero.', function(){ 28 this.input 29 .val('2012-03-05') 30 .datepicker({format: 'yyyy-m-dd'}) 31 .datepicker('setValue'); 32 equal(this.input.val().split('-')[1], '3'); 33 }); 34 35 test('mm: Month, leading zero.', function(){ 36 this.input 37 .val('2012-3-5') 38 .datepicker({format: 'yyyy-mm-dd'}) 39 .datepicker('setValue'); 40 equal(this.input.val().split('-')[1], '03'); 41 }); 42 43 test('M: Month shortname.', function(){ 44 this.input 45 .val('2012-Mar-05') 46 .datepicker({format: 'yyyy-M-dd'}) 47 .datepicker('setValue'); 48 equal(this.input.val().split('-')[1], 'Mar'); 49 }); 50 51 test('MM: Month full name.', function(){ 52 this.input 53 .val('2012-March-5') 54 .datepicker({format: 'yyyy-MM-dd'}) 55 .datepicker('setValue'); 56 equal(this.input.val().split('-')[1], 'March'); 57 }); 58 59 test('yy: Year, two-digit.', function(){ 60 this.input 61 .val('2012-03-05') 62 .datepicker({format: 'yy-mm-dd'}) 63 .datepicker('setValue'); 64 equal(this.input.val().split('-')[0], '12'); 65 }); 66 67 test('yyyy: Year, four-digit.', function(){ 68 this.input 69 .val('2012-03-5') 70 .datepicker({format: 'yyyy-mm-dd'}) 71 .datepicker('setValue'); 72 equal(this.input.val().split('-')[0], '2012'); 73 }); 74 75 test('dd-mm-yyyy: Regression: Prevent potential month overflow in small-to-large formats (Mar 31, 2012 -> Mar 01, 2012)', function(){ 76 this.input 77 .val('31-03-2012') 78 .datepicker({format: 'dd-mm-yyyy'}) 79 .datepicker('setValue'); 80 equal(this.input.val(), '31-03-2012'); 81 }); 82 83 test('dd-mm-yyyy: Leap day', function(){ 84 this.input 85 .val('29-02-2012') 86 .datepicker({format: 'dd-mm-yyyy'}) 87 .datepicker('setValue'); 88 equal(this.input.val(), '29-02-2012'); 89 }); 90 91 test('+1d: Tomorrow', patch_date(function(Date){ 92 Date.now = new Date(2012, 2, 15); 93 this.input 94 .val('+1d') 95 .datepicker({format: 'dd-mm-yyyy'}) 96 .datepicker('setValue'); 97 equal(this.input.val(), '16-03-2012'); 98 })); 99 100 test('-1d: Yesterday', patch_date(function(Date){ 101 Date.now = new Date(2012, 2, 15); 102 this.input 103 .val('-1d') 104 .datepicker({format: 'dd-mm-yyyy'}) 105 .datepicker('setValue'); 106 equal(this.input.val(), '14-03-2012'); 107 })); 108 109 test('+1w: Next week', patch_date(function(Date){ 110 Date.now = new Date(2012, 2, 15); 111 this.input 112 .val('+1w') 113 .datepicker({format: 'dd-mm-yyyy'}) 114 .datepicker('setValue'); 115 equal(this.input.val(), '22-03-2012'); 116 })); 117 118 test('-1w: Last week', patch_date(function(Date){ 119 Date.now = new Date(2012, 2, 15); 120 this.input 121 .val('-1w') 122 .datepicker({format: 'dd-mm-yyyy'}) 123 .datepicker('setValue'); 124 equal(this.input.val(), '08-03-2012'); 125 })); 126 127 test('+1m: Next month', patch_date(function(Date){ 128 Date.now = new Date(2012, 2, 15); 129 this.input 130 .val('+1m') 131 .datepicker({format: 'dd-mm-yyyy'}) 132 .datepicker('setValue'); 133 equal(this.input.val(), '15-04-2012'); 134 })); 135 136 test('-1m: Last month', patch_date(function(Date){ 137 Date.now = new Date(2012, 2, 15); 138 this.input 139 .val('-1m') 140 .datepicker({format: 'dd-mm-yyyy'}) 141 .datepicker('setValue'); 142 equal(this.input.val(), '15-02-2012'); 143 })); 144 145 test('+1y: Next year', patch_date(function(Date){ 146 Date.now = new Date(2012, 2, 15); 147 this.input 148 .val('+1y') 149 .datepicker({format: 'dd-mm-yyyy'}) 150 .datepicker('setValue'); 151 equal(this.input.val(), '15-03-2013'); 152 })); 153 154 test('-1y: Last year', patch_date(function(Date){ 155 Date.now = new Date(2012, 2, 15); 156 this.input 157 .val('-1y') 158 .datepicker({format: 'dd-mm-yyyy'}) 159 .datepicker('setValue'); 160 equal(this.input.val(), '15-03-2011'); 161 })); 162 163 test('-1y +2m: Multiformat', patch_date(function(Date){ 164 Date.now = new Date(2012, 2, 15); 165 this.input 166 .val('-1y +2m') 167 .datepicker({format: 'dd-mm-yyyy'}) 168 .datepicker('setValue'); 169 equal(this.input.val(), '15-05-2011'); 170 }));
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |