date_test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var Ember = require('ember');
  19. var App = require('app');
  20. var validator = require('utils/validator');
  21. var date = require('utils/date');
  22. describe('date', function () {
  23. var correct_tests = Em.A([
  24. {t: 1349752195000, e: 'Tue, Oct 09, 2012 03:09', e2: 'Tue Oct 09 2012'},
  25. {t: 1367752195000, e: 'Sun, May 05, 2013 11:09', e2: 'Sun May 05 2013'},
  26. {t: 1369952195000, e: 'Thu, May 30, 2013 22:16', e2: 'Thu May 30 2013'}
  27. ]);
  28. var incorrect_tests = Em.A([
  29. {t: null},
  30. {t: ''},
  31. {t: false},
  32. {t: []},
  33. {t: {}},
  34. {t: undefined},
  35. {t: function(){}}
  36. ]);
  37. describe('#dateFormat', function() {
  38. describe('Correct timestamps', function(){
  39. correct_tests.forEach(function(test) {
  40. it(test.t, function() {
  41. expect(date.dateFormat(test.t)).to.equal(test.e);
  42. });
  43. });
  44. });
  45. describe('Incorrect timestamps', function() {
  46. incorrect_tests.forEach(function(test) {
  47. it(test.t, function() {
  48. expect(date.dateFormat(test.t)).to.equal(test.t);
  49. });
  50. });
  51. });
  52. });
  53. describe('#dateFormatShort', function() {
  54. describe('Correct timestamps', function() {
  55. correct_tests.forEach(function(test) {
  56. it(test.t, function() {
  57. expect(date.dateFormatShort(test.t)).to.equal(test.e2);
  58. });
  59. });
  60. });
  61. it('Today timestamp', function() {
  62. var now = new Date();
  63. var then = new Date(now.getFullYear(),now.getUTCMonth(),now.getUTCDate(),0,0,0);
  64. expect(date.dateFormatShort(then.getTime() + 10*3600*1000)).to.equal('Today 10:00:00');
  65. });
  66. describe('Incorrect timestamps', function() {
  67. incorrect_tests.forEach(function(test) {
  68. it(test.t, function() {
  69. expect(date.dateFormatShort(test.t)).to.equal(test.t);
  70. });
  71. });
  72. });
  73. });
  74. describe('#timingFormat', function() {
  75. var tests = Em.A([
  76. {i: '30', e:'30 ms'},
  77. {i: '300', e:'300 ms'},
  78. {i: '999', e:'999 ms'},
  79. {i: '1000', e:'1.00 secs'},
  80. {i: '3000', e:'3.00 secs'},
  81. {i: '35000', e:'35.00 secs'},
  82. {i: '350000', e:'350.00 secs'},
  83. {i: '999999', e:'1000.00 secs'},
  84. {i: '1000000', e:'16.67 mins'},
  85. {i: '3500000', e:'58.33 mins'},
  86. {i: '35000000', e:'9.72 hours'},
  87. {i: '350000000', e:'4.05 days'},
  88. {i: '3500000000', e:'40.51 days'},
  89. {i: '35000000000', e:'405.09 days'}
  90. ]);
  91. describe('Correct data', function(){
  92. tests.forEach(function(test) {
  93. it(test.t, function() {
  94. expect(date.timingFormat(test.i)).to.equal(test.e);
  95. });
  96. });
  97. });
  98. describe('Incorrect data', function(){
  99. incorrect_tests.forEach(function(test) {
  100. it(test.t, function() {
  101. expect(date.timingFormat(test.t)).to.equal(null);
  102. });
  103. });
  104. });
  105. });
  106. describe('#duration', function() {
  107. var tests = Em.A([
  108. {startTime: 1, endTime: 2, e: 1},
  109. {startTime: 0, endTime: 2000, e: 0}
  110. ]);
  111. tests.forEach(function(test) {
  112. it(test.startTime + ' ' + test.endTime, function() {
  113. expect(date.duration(test.startTime, test.endTime)).to.equal(test.e);
  114. });
  115. });
  116. });
  117. });