Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

1034 linhas
40 KiB

  1. var chai = require('chai')
  2. , moment = require('./index')
  3. chai.should()
  4. moment.updateLocale('en'
  5. , { week:
  6. { dow: 6
  7. , doy: 12
  8. }
  9. , longDateFormat:
  10. { LT: 'h:mm A'
  11. , LTS: 'h:mm:ss A'
  12. , L: 'jYYYY/jMM/jDD'
  13. , LL: 'jD jMMMM jYYYY'
  14. , LLL: 'jD jMMMM jYYYY LT'
  15. , LLLL: 'dddd, jD jMMMM jYYYY LT'
  16. }
  17. }
  18. )
  19. describe('moment', function() {
  20. describe('#parse', function() {
  21. it('should parse gregorian dates', function() {
  22. var m = moment('1980/5/15 07:10:20', 'YYYY/M/D hh:mm:ss')
  23. m.format('YYYY-MM-DD hh:mm:ss').should.be.equal('1980-05-15 07:10:20')
  24. m.milliseconds().should.be.equal(0)
  25. })
  26. it('should parse correctly when input is only time', function() {
  27. var m = moment('07:10:20', 'hh:mm:ss')
  28. m.format('YYYY-MM-DD hh:mm:ss').should.be.equal('0000-01-01 07:10:20')
  29. })
  30. it('should parse when only Jalaali year is in the format', function() {
  31. var m = moment('05 1359 15', 'MM jYYYY DD')
  32. m.format('YYYY-MM-DD').should.be.equal('1980-05-15')
  33. m = moment('05 59 15', 'MM jYY DD')
  34. m.format('YYYY-MM-DD').should.be.equal('1980-05-15')
  35. })
  36. it('should parse when only Jalaali month is in the format', function() {
  37. var m = moment('1980 2 15', 'YYYY jM D')
  38. m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
  39. })
  40. it('should parse when only Jalaali month string is in the format', function() {
  41. var m = moment('1980 Ord 15', 'YYYY jMMM D')
  42. m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
  43. m = moment('1980 Ordibehesht 15', 'YYYY jMMMM D')
  44. m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
  45. })
  46. it('should parse when only Jalaali date is in the format', function() {
  47. var m = moment('1980 24 5', 'YYYY jD M')
  48. m.format('YYYY-MM-DD').should.be.equal('1980-05-13')
  49. })
  50. it('should parse when Jalaali year and month are in the format', function() {
  51. var m = moment('15 1359 2', 'D jYYYY jM')
  52. m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
  53. m = moment('1392 7', 'jYYYY jM')
  54. m.format('YYYY-MM-DD').should.be.equal('2013-09-23')
  55. })
  56. it('should parse when Jalaali year and date are in the format', function() {
  57. var m = moment('24 1359 5', 'jD jYYYY M')
  58. m.format('YYYY-MM-DD').should.be.equal('1980-05-13')
  59. })
  60. it('should parse when Jalaali month and date are in the format', function() {
  61. var m = moment('24 1980 2', 'jD YYYY jM')
  62. m.format('YYYY-MM-DD').should.be.equal('1980-05-14')
  63. })
  64. it('should parse when Jalaali year, month and date are in the format', function() {
  65. var m = moment('24 1359 2', 'jD jYYYY jM')
  66. m.format('YYYY-MM-DD').should.be.equal('1980-05-14')
  67. })
  68. it('should parse with complex format', function() {
  69. var m = moment('15 24 50 1980 50 5 12', 'D jD jYYYY YYYY M M jM')
  70. m.format('YYYY-MM-DD').should.be.equal('1980-05-15')
  71. })
  72. it('should parse format result', function() {
  73. var f = 'jYYYY/jM/jD hh:mm:ss.SSS a'
  74. , m = moment()
  75. moment(m.format(f), f).isSame(m).should.be.true
  76. })
  77. it('should be able to parse in utc', function() {
  78. var m = moment.utc('1359/2/24 07:10:20', 'jYYYY/jM/jD hh:mm:ss')
  79. m.format('YYYY-MM-DD hh:mm:ss Z').should.be.equal('1980-05-14 07:10:20 +00:00')
  80. })
  81. it('should parse with a format array', function() {
  82. var p1 = 'jYY jM jD'
  83. , p2 = 'jM jD jYY'
  84. , p3 = 'jD jYY jM'
  85. , m
  86. m = moment('60 11 12', ['D YY M', 'M D YY', 'YY M D'])
  87. m.format('YY-MM-DD').should.be.equal('60-11-12')
  88. m = moment('10 11 12', [p1, p2, p3])
  89. m.format('jYY-jMM-jDD').should.be.equal('10-11-12')
  90. m = moment('10 11 12', [p2, p3, p1])
  91. m.format('jYY-jMM-jDD').should.be.equal('12-10-11')
  92. m = moment('10 11 12', [p3, p1, p2])
  93. m.format('jYY-jMM-jDD').should.be.equal('11-12-10')
  94. m = moment('10 11 12', [p3, p2, p1])
  95. m.format('jYY-jMM-jDD').should.be.equal('11-12-10')
  96. m = moment('60-11-12', [p3, p2, p1])
  97. m.format('jYY-jMM-jDD').should.be.equal('60-11-12')
  98. m = moment('60 11 12', [p3, p2, p1])
  99. m.format('jYY-jMM-jDD').should.be.equal('60-11-12')
  100. m = moment('60 8 31', ['YY M D', 'jYY jM jD'])
  101. m.format('YY-MM-DD').should.be.equal('60-08-31')
  102. m = moment('60 8 31', ['jYY jM jD', 'YY M D'])
  103. m.format('YY-MM-DD').should.be.equal('60-08-31')
  104. m = moment('60 5 31', ['YY M D', 'jYY jM jD'])
  105. m.format('YY-MM-DD').should.be.equal('60-05-31')
  106. m = moment('60 5 31', ['jYY jM jD', 'YY M D'])
  107. m.format('jYY-jMM-jDD').should.be.equal('60-05-31')
  108. })
  109. it('should return valid moment instance if years is less than 3178', function () {
  110. var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
  111. m.format('jYYYY-jMM-jDD').should.be.equal('3177-01-01')
  112. })
  113. it('should return invalid moment instance if years is larger than 3177 (Jalali)', function () {
  114. var m = moment('3178-01-01', 'jYYYY-jMM-jDD')
  115. m.isValid().should.be.false
  116. m.jYear().should.be.NaN
  117. m.jMonth().should.be.NaN
  118. m.jDate().should.be.NaN
  119. })
  120. it('should return invalid moment instance if years is larger than 3177 (Gregorian)', function () {
  121. var m = moment('9999-01-01','YYYY-MM-DD')
  122. m.isValid().should.be.false
  123. m.jYear().should.be.NaN
  124. m.jMonth().should.be.NaN
  125. m.jDate().should.be.NaN
  126. })
  127. it('should return invalid moment instance if years is larger than 3177 (timestamp)', function () {
  128. var m = moment(64060576200000)
  129. m.isValid().should.be.false
  130. m.jYear().should.be.NaN
  131. m.jMonth().should.be.NaN
  132. m.jDate().should.be.NaN
  133. })
  134. it('should return invalid moment instance if years is larger than 3177 (timestamp)', function () {
  135. var m = moment(new Date(64060576200000))
  136. m.isValid().should.be.false
  137. m.jYear().should.be.NaN
  138. m.jMonth().should.be.NaN
  139. m.jDate().should.be.NaN
  140. })
  141. })
  142. describe('#format', function() {
  143. it('should work normally when there is no Jalaali token', function() {
  144. var m = moment('1980-05-15 07:10:20')
  145. m.format('YYYY-MM-DD hh:mm:ss').should.be.equal('1980-05-15 07:10:20')
  146. })
  147. it('should format to Jalaali with Jalaali tokens', function() {
  148. var m = moment('1980-05-15 07:10:20')
  149. m.format('jYYYY-jMM-jDD hh:mm:ss').should.be.equal('1359-02-25 07:10:20')
  150. })
  151. it('should format with escaped and unescaped tokens', function() {
  152. var m = moment('1980-05-15')
  153. m.format('[My] birt\\h \\y[ea]r [is] jYYYY or YYYY').should.be.equal('My birth year is 1359 or 1980')
  154. })
  155. it('should format with mixed tokens', function() {
  156. var m = moment('1980-05-15')
  157. m.format('jYYYY/jMM/jDD = YYYY-MM-DD').should.be.equal('1359/02/25 = 1980-05-15')
  158. })
  159. it('should format with jMo', function() {
  160. var m = moment('1980-05-15')
  161. m.format('jMo').should.be.equal('2nd')
  162. })
  163. it('should format with jM', function() {
  164. var m = moment('1980-05-15')
  165. m.format('jM').should.be.equal('2')
  166. })
  167. it('should format with jMM', function() {
  168. var m = moment('1980-05-15')
  169. m.format('jMM').should.be.equal('02')
  170. })
  171. it('should format with jMMM', function() {
  172. var m = moment('1980-05-15')
  173. m.format('jMMM').should.be.equal('Ord')
  174. })
  175. it('should format with jMMMM', function() {
  176. var m = moment('1980-05-15')
  177. m.format('jMMMM').should.be.equal('Ordibehesht')
  178. })
  179. it('should format with jDo', function() {
  180. var m = moment('1980-05-15')
  181. m.format('jDo').should.be.equal('25th')
  182. })
  183. it('should format with jD', function() {
  184. var m = moment('1980-05-15')
  185. m.format('jD').should.be.equal('25')
  186. })
  187. it('should format with jDD', function() {
  188. var m = moment('1980-05-15')
  189. m.format('jDD').should.be.equal('25')
  190. m = moment('1980-05-22')
  191. m.format('jDD').should.be.equal('01')
  192. })
  193. it('should format with jDDD', function() {
  194. var m = moment('1980-05-15')
  195. m.format('jDDD').should.be.equal('56')
  196. })
  197. it('should format with jDDDo', function() {
  198. var m = moment('1980-05-15')
  199. m.format('jDDDo').should.be.equal('56th')
  200. })
  201. it('should format with jDDDD', function() {
  202. var m = moment('1980-05-15')
  203. m.format('jDDDD').should.be.equal('056')
  204. m = moment('1980-03-21')
  205. m.format('jDDDD').should.be.equal('001')
  206. })
  207. it('should format with jwo', function() {
  208. var m = moment('1980-05-15')
  209. m.format('jwo').should.be.equal('9th')
  210. })
  211. it('should format with jw', function() {
  212. var m = moment('1980-05-15')
  213. m.format('jw').should.be.equal('9')
  214. })
  215. it('should format with jww', function() {
  216. var m = moment('1980-05-15')
  217. m.format('jww').should.be.equal('09')
  218. m = moment('1980-04-23')
  219. m.format('jww').should.be.equal('06')
  220. })
  221. it('should format with jYY', function() {
  222. var m = moment('1980-05-15')
  223. m.format('jYY').should.be.equal('59')
  224. })
  225. it('should format with jYYYY', function() {
  226. var m = moment('1980-05-15')
  227. m.format('jYYYY').should.be.equal('1359')
  228. })
  229. it('should format with jYYYYY', function() {
  230. var m = moment('1980-05-15')
  231. m.format('jYYYYY').should.be.equal('01359')
  232. })
  233. it('should format with jgg', function() {
  234. var m = moment('1980-05-15')
  235. m.format('jgg').should.be.equal('59')
  236. })
  237. it('should format with jgggg', function() {
  238. var m = moment('1980-05-15')
  239. m.format('jgggg').should.be.equal('1359')
  240. })
  241. it('should format with jggggg', function() {
  242. var m = moment('1980-05-15')
  243. m.format('jggggg').should.be.equal('01359')
  244. })
  245. it('should work with long date formats too', function() {
  246. var m = moment('1980-05-15')
  247. m.format('LT').should.be.equal('12:00 AM')
  248. m.format('LTS').should.be.equal('12:00:00 AM')
  249. m.format('L').should.be.equal('1359/02/25')
  250. m.format('l').should.be.equal('1359/2/25')
  251. m.format('LL').should.be.equal('25 Ordibehesht 1359')
  252. m.format('ll').should.be.equal('25 Ord 1359')
  253. m.format('LLL').should.be.equal('25 Ordibehesht 1359 12:00 AM')
  254. m.format('lll').should.be.equal('25 Ord 1359 12:00 AM')
  255. m.format('LLLL').should.be.equal('Thursday, 25 Ordibehesht 1359 12:00 AM')
  256. m.format('llll').should.be.equal('Thu, 25 Ord 1359 12:00 AM')
  257. })
  258. it('should work with long date formats too if we have time', function() {
  259. var m = moment('1980-05-15 12:15:45')
  260. m.format('LT').should.be.equal('12:15 PM')
  261. m.format('LTS').should.be.equal('12:15:45 PM')
  262. m.format('L').should.be.equal('1359/02/25')
  263. m.format('l').should.be.equal('1359/2/25')
  264. m.format('LL').should.be.equal('25 Ordibehesht 1359')
  265. m.format('ll').should.be.equal('25 Ord 1359')
  266. m.format('LLL').should.be.equal('25 Ordibehesht 1359 12:15 PM')
  267. m.format('lll').should.be.equal('25 Ord 1359 12:15 PM')
  268. m.format('LLLL').should.be.equal('Thursday, 25 Ordibehesht 1359 12:15 PM')
  269. m.format('llll').should.be.equal('Thu, 25 Ord 1359 12:15 PM')
  270. })
  271. })
  272. describe('#jYear', function() {
  273. it('should return Jalaali year', function() {
  274. var m = moment('1980-05-15')
  275. m.jYear().should.be.equal(1359)
  276. })
  277. it('should set Jalaali year', function() {
  278. var m = moment('1980-05-15')
  279. m.jYear(1392)
  280. m.format('jYYYY/jM/jD').should.be.equal('1392/2/25')
  281. m = moment('2013-03-20')
  282. m.format('jYY/jM/jD').should.be.equal('91/12/30')
  283. m.jYear(1392)
  284. m.format('jYY/jM/jD').should.be.equal('92/12/29')
  285. })
  286. it('should also has jYears alias', function() {
  287. moment.fn.jYear.should.be.equal(moment.fn.jYears)
  288. })
  289. it('should return invalid moment instance if years is larger than 31778', function () {
  290. var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
  291. m.jYear(3178)
  292. m.isValid().should.be.false
  293. m.jYear().should.be.NaN
  294. m.jMonth().should.be.NaN
  295. m.jDate().should.be.NaN
  296. })
  297. })
  298. describe('#jMonth', function() {
  299. it('should return Jalaali month', function() {
  300. var m = moment('1980-05-15')
  301. m.jMonth().should.be.equal(1)
  302. })
  303. it('should set Jalaali month', function() {
  304. var m = moment('1980-05-15')
  305. m.jMonth(4)
  306. m.format('jYYYY/jM/jD').should.be.equal('1359/5/25')
  307. m = moment('2012-05-20')
  308. m.format('jYY/jM/jD').should.be.equal('91/2/31')
  309. m.jMonth(11)
  310. m.format('jYY/jM/jD').should.be.equal('91/12/30')
  311. m = moment('2013-05-21')
  312. m.format('jYY/jM/jD').should.be.equal('92/2/31')
  313. m.jMonth(11)
  314. m.format('jYY/jM/jD').should.be.equal('92/12/29')
  315. })
  316. it('should also has jMonths alias', function() {
  317. moment.fn.jMonth.should.be.equal(moment.fn.jMonths)
  318. })
  319. })
  320. describe('#jDate', function() {
  321. it('should return Jalaali date', function() {
  322. var m = moment('1980-05-15')
  323. m.jDate().should.be.equal(25)
  324. })
  325. it('should set Jalaali date', function() {
  326. var m = moment('1980-05-15')
  327. m.jDate(30)
  328. m.format('jYYYY/jM/jD').should.be.equal('1359/2/30')
  329. m = moment('2013-03-01')
  330. m.format('jYY/jM/jD').should.be.equal('91/12/11')
  331. m.jDate(29)
  332. m.format('jYY/jM/jD').should.be.equal('91/12/29')
  333. m.jDate(30)
  334. m.format('jYY/jM/jD').should.be.equal('91/12/30')
  335. m.jDate(30)
  336. m.format('jYY/jM/jD').should.be.equal('91/12/30')
  337. m.jDate(31)
  338. m.format('jYY/jM/jD').should.be.equal('92/1/1')
  339. m.jDate(90)
  340. m.format('jYY/jM/jD').should.be.equal('92/3/28')
  341. })
  342. it('should also has jDates alias', function() {
  343. moment.fn.jDate.should.be.equal(moment.fn.jDates)
  344. })
  345. })
  346. describe('#jDayOfYear', function() {
  347. it('should return Jalaali date of year', function() {
  348. var m = moment('1980-05-15')
  349. m.jDayOfYear().should.be.equal(56)
  350. m = moment('1981-03-21')
  351. m.jDayOfYear().should.be.equal(1)
  352. m = moment('1982-03-20')
  353. m.jDayOfYear().should.be.equal(365)
  354. m = moment('1984-03-20')
  355. m.jDayOfYear().should.be.equal(366)
  356. })
  357. it('should set Jalaali date of year', function() {
  358. var m = moment('1980-05-15')
  359. m.jDayOfYear(30)
  360. m.format('jYYYY/jM/jD').should.be.equal('1359/1/30')
  361. m.jDayOfYear(364)
  362. m.format('jYY/jM/jD').should.be.equal('59/12/28')
  363. m.jDayOfYear(365)
  364. m.format('jYY/jM/jD').should.be.equal('59/12/29')
  365. m.jDayOfYear(366)
  366. m.format('jYY/jM/jD').should.be.equal('60/1/1')
  367. m.jDayOfYear(1)
  368. m.format('jYY/jM/jD').should.be.equal('60/1/1')
  369. m.jDayOfYear(90)
  370. m.format('jYY/jM/jD').should.be.equal('60/3/28')
  371. m.jDayOfYear(365 + 365)
  372. m.format('jYY/jM/jD').should.be.equal('61/12/29')
  373. })
  374. })
  375. describe('#jWeek', function() {
  376. it('should return Jalaali week of year', function() {
  377. var m = moment('1980-05-15')
  378. m.jWeek().should.be.equal(9)
  379. m.jDayOfYear(1)
  380. m.format('jYY/jM/jD').should.be.equal('59/1/1')
  381. m.jWeek().should.be.equal(1)
  382. m.jDayOfYear(8)
  383. m.format('jYY/jM/jD').should.be.equal('59/1/8')
  384. m.jWeek().should.be.equal(2)
  385. m.jDayOfYear(14)
  386. m.format('jYY/jM/jD').should.be.equal('59/1/14')
  387. m.jWeek().should.be.equal(3)
  388. m.jDayOfYear(364)
  389. m.format('jYY/jM/jD').should.be.equal('59/12/28')
  390. m.jWeek().should.be.equal(53)
  391. m.jDayOfYear(365)
  392. m.format('jYY/jM/jD').should.be.equal('59/12/29')
  393. m.jWeek().should.be.equal(53)
  394. m.jDayOfYear(366)
  395. m.format('jYY/jM/jD').should.be.equal('60/1/1')
  396. m.jWeek().should.be.equal(1)
  397. m.jDayOfYear(363)
  398. m.format('jYY/jM/jD').should.be.equal('60/12/27')
  399. m.jWeek().should.be.equal(52)
  400. m.jDayOfYear(365)
  401. m.format('jYY/jM/jD').should.be.equal('60/12/29')
  402. m.jWeek().should.be.equal(1)
  403. m.jDayOfYear(366)
  404. m.format('jYY/jM/jD').should.be.equal('61/1/1')
  405. m.jWeek().should.be.equal(1)
  406. m.jDayOfYear(365)
  407. m.format('jYY/jM/jD').should.be.equal('61/12/29')
  408. m.jWeek().should.be.equal(1)
  409. m.jDayOfYear(365)
  410. m.format('jYY/jM/jD').should.be.equal('61/12/29')
  411. m.jWeek().should.be.equal(1)
  412. m.jDayOfYear(366)
  413. m.format('jYY/jM/jD').should.be.equal('62/1/1')
  414. m.jWeek().should.be.equal(1)
  415. m.jDayOfYear(365)
  416. m.format('jYY/jM/jD').should.be.equal('62/12/29')
  417. m.jWeek().should.be.equal(1)
  418. m.jDayOfYear(366)
  419. m.format('jYY/jM/jD').should.be.equal('62/12/30')
  420. m.jWeek().should.be.equal(1)
  421. m.jDayOfYear(365)
  422. m.format('jYY/jM/jD').should.be.equal('62/12/29')
  423. m.jWeek().should.be.equal(1)
  424. m.jDayOfYear(366)
  425. m.format('jYY/jM/jD').should.be.equal('62/12/30')
  426. m.jWeek().should.be.equal(1)
  427. m.jDayOfYear(358)
  428. m.format('jYY/jM/jD').should.be.equal('62/12/22')
  429. m.jWeek().should.be.equal(52)
  430. m.jDayOfYear(359)
  431. m.format('jYY/jM/jD').should.be.equal('62/12/23')
  432. m.jWeek().should.be.equal(52)
  433. m.jDayOfYear(360)
  434. m.format('jYY/jM/jD').should.be.equal('62/12/24')
  435. m.jWeek().should.be.equal(52)
  436. m.jDayOfYear(361)
  437. m.format('jYY/jM/jD').should.be.equal('62/12/25')
  438. m.jWeek().should.be.equal(52)
  439. m.jDayOfYear(362)
  440. m.format('jYY/jM/jD').should.be.equal('62/12/26')
  441. m.jWeek().should.be.equal(52)
  442. m.jDayOfYear(363)
  443. m.format('jYY/jM/jD').should.be.equal('62/12/27')
  444. m.jWeek().should.be.equal(1)
  445. m.jDayOfYear(364)
  446. m.format('jYY/jM/jD').should.be.equal('62/12/28')
  447. m.jWeek().should.be.equal(1)
  448. m.jDayOfYear(365)
  449. m.format('jYY/jM/jD').should.be.equal('62/12/29')
  450. m.jWeek().should.be.equal(1)
  451. })
  452. it('should set Jalaali week of year', function() {
  453. var m = moment('1980-05-15')
  454. m.jWeek(1)
  455. m.format('jYY/jM/jD').should.be.equal('58/12/30')
  456. m.jWeek(9)
  457. m.format('jYY/jM/jD').should.be.equal('59/2/25')
  458. m.jWeek(52)
  459. m.format('jYY/jM/jD').should.be.equal('59/12/21')
  460. m.jWeek(53)
  461. m.format('jYY/jM/jD').should.be.equal('59/12/28')
  462. m.jWeek(1)
  463. m.format('jYY/jM/jD').should.be.equal('58/12/30')
  464. m.jWeek(0)
  465. m.format('jYY/jM/jD').should.be.equal('58/12/23')
  466. m.jWeek(-1)
  467. m.format('jYY/jM/jD').should.be.equal('57/12/17')
  468. })
  469. })
  470. describe('#jWeekYear', function() {
  471. it('should return Jalaali week year', function() {
  472. var m = moment('1980-05-15')
  473. m.jWeekYear().should.be.equal(1359)
  474. m.jDayOfYear(1)
  475. m.format('jYY/jM/jD').should.be.equal('59/1/1')
  476. m.jWeekYear().should.be.equal(1359)
  477. m.jDayOfYear(364)
  478. m.format('jYY/jM/jD').should.be.equal('59/12/28')
  479. m.jWeekYear().should.be.equal(1359)
  480. m.jDayOfYear(365)
  481. m.format('jYY/jM/jD').should.be.equal('59/12/29')
  482. m.jWeekYear().should.be.equal(1359)
  483. m.jDayOfYear(366)
  484. m.format('jYY/jM/jD').should.be.equal('60/1/1')
  485. m.jWeekYear().should.be.equal(1360)
  486. m.jDayOfYear(363)
  487. m.format('jYY/jM/jD').should.be.equal('60/12/27')
  488. m.jWeekYear().should.be.equal(1360)
  489. m.jDayOfYear(365)
  490. m.format('jYY/jM/jD').should.be.equal('60/12/29')
  491. m.jWeekYear().should.be.equal(1361)
  492. m.jDayOfYear(366)
  493. m.format('jYY/jM/jD').should.be.equal('61/1/1')
  494. m.jWeekYear().should.be.equal(1361)
  495. m.jDayOfYear(365)
  496. m.format('jYY/jM/jD').should.be.equal('61/12/29')
  497. m.jWeekYear().should.be.equal(1362)
  498. m.jDayOfYear(366)
  499. m.format('jYY/jM/jD').should.be.equal('62/1/1')
  500. m.jWeekYear().should.be.equal(1362)
  501. m.jDayOfYear(367)
  502. m.format('jYY/jM/jD').should.be.equal('63/1/1')
  503. m.jWeekYear().should.be.equal(1363)
  504. m.jDayOfYear(365)
  505. m.format('jYY/jM/jD').should.be.equal('63/12/29')
  506. m.jWeekYear().should.be.equal(1364)
  507. m.jDayOfYear(366)
  508. m.format('jYY/jM/jD').should.be.equal('64/1/1')
  509. m.jWeekYear().should.be.equal(1364)
  510. m.jDayOfYear(365)
  511. m.format('jYY/jM/jD').should.be.equal('64/12/29')
  512. m.jWeekYear().should.be.equal(1365)
  513. m.jDayOfYear(366)
  514. m.format('jYY/jM/jD').should.be.equal('65/1/1')
  515. m.jWeekYear().should.be.equal(1365)
  516. m.jDayOfYear(358)
  517. m.format('jYY/jM/jD').should.be.equal('65/12/22')
  518. m.jWeekYear().should.be.equal(1365)
  519. m.jDayOfYear(359)
  520. m.format('jYY/jM/jD').should.be.equal('65/12/23')
  521. m.jWeekYear().should.be.equal(1365)
  522. m.jDayOfYear(365)
  523. m.format('jYY/jM/jD').should.be.equal('65/12/29')
  524. m.jWeekYear().should.be.equal(1365)
  525. m.jDayOfYear(366)
  526. m.format('jYY/jM/jD').should.be.equal('66/1/1')
  527. m.jWeekYear().should.be.equal(1366)
  528. })
  529. it('should set Jalaali week year', function() {
  530. var m = moment('1980-05-15')
  531. m.jWeekYear(1360)
  532. m.format('jYY/jM/jD').should.be.equal('60/2/25')
  533. m.jWeekYear(1364)
  534. m.format('jYY/jM/jD').should.be.equal('64/2/25')
  535. m.jDayOfYear(365)
  536. m.format('jYY/jM/jD').should.be.equal('64/12/29')
  537. m.jWeekYear(1364)
  538. m.format('jYY/jM/jD').should.be.equal('63/12/29')
  539. m.jWeekYear(1365)
  540. m.format('jYY/jM/jD').should.be.equal('64/12/29')
  541. })
  542. })
  543. describe('#startOf', function() {
  544. it('should work as expected without jYear and jMonth', function() {
  545. var m = moment('1980-05-15 07:10:20')
  546. m.startOf('year').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-01-01 00:00:00')
  547. m = moment('1980-05-15 07:10:20')
  548. m.startOf('month').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-01 00:00:00')
  549. m = moment('1980-05-15 07:10:20')
  550. m.startOf('day').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-15 00:00:00')
  551. m = moment('1980-05-15 07:10:20')
  552. m.startOf('week').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-10 00:00:00')
  553. })
  554. it('should return start of Jalaali year, month and date', function() {
  555. var m = moment('1985-05-15 07:10:20')
  556. m.startOf('jYear').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1364-01-01 00:00:00')
  557. m = moment('1980-05-15 07:10:20')
  558. m.startOf('jMonth').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-01 00:00:00')
  559. m = moment('1980-05-15 07:10:20')
  560. m.startOf('day').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-25 00:00:00')
  561. m = moment('1980-05-15 07:10:20')
  562. m.startOf('week').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-20 00:00:00')
  563. })
  564. })
  565. describe('#endOf', function() {
  566. it('should work as expected without jYear and jMonth', function() {
  567. var m = moment('1980-05-15 07:10:20')
  568. m.endOf('year').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-12-31 23:59:59')
  569. m = moment('1980-05-15 07:10:20')
  570. m.endOf('month').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-31 23:59:59')
  571. m = moment('1980-05-15 07:10:20')
  572. m.endOf('day').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-15 23:59:59')
  573. m = moment('1980-05-15 07:10:20')
  574. m.endOf('week').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-16 23:59:59')
  575. })
  576. it('should return end of Jalaali year, month and date', function() {
  577. var m = moment('1985-05-15 07:10:20')
  578. m.endOf('jYear').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1364-12-29 23:59:59')
  579. m = moment('1980-05-15 07:10:20')
  580. m.endOf('jMonth').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-31 23:59:59')
  581. m = moment('1980-05-15 07:10:20')
  582. m.endOf('day').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-25 23:59:59')
  583. m = moment('1980-05-15 07:10:20')
  584. m.endOf('week').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-26 23:59:59')
  585. })
  586. })
  587. describe('#isValid', function() {
  588. it('should return true when a valid date is parsed and false otherwise', function() {
  589. var jf = 'jYYYY/jMM/jDD'
  590. , gf = 'YYYY-MM-DD'
  591. moment('1980-05-15', gf).isValid().should.be.true
  592. moment('1980-05-29', gf).isValid().should.be.true
  593. moment('1980-06-31', gf).isValid().should.be.false
  594. moment('1359 xordibehesht 25', 'jYYYY jMMMM jD').isValid().should.be.false
  595. moment('1359/02/25', jf).isValid().should.be.true
  596. moment('1359/02/31', jf).isValid().should.be.true
  597. moment('1359/04/30', jf).isValid().should.be.true
  598. moment('1359/04/32', jf).isValid().should.be.false
  599. moment('1359/12/29', jf).isValid().should.be.true
  600. moment('1359/12/30', jf).isValid().should.be.false
  601. moment('1359/12/31', jf).isValid().should.be.false
  602. moment('1359/13/01', jf).isValid().should.be.false
  603. moment('1393/11/00', jf).isValid().should.be.false
  604. })
  605. })
  606. describe('#isValid-strict', function () {
  607. it('should return false when gregorian date is not strictly valid', function () {
  608. var gf = 'YYYY-MM-DD'
  609. moment('1980-05-15', gf).isValid().should.be.true
  610. moment('1980-05-31', gf).isValid().should.be.true
  611. moment('1980-05-311', gf).isValid().should.be.true
  612. moment('1980-05-311', gf, true).isValid().should.be.false
  613. })
  614. it('should return false when jalaali date is not strictly valid', function () {
  615. var jf = 'jYYYY/jMM/jDD'
  616. moment('1359/02/25', jf).isValid().should.be.true
  617. moment('1359/02/31', jf).isValid().should.be.true
  618. moment('1359/02/311', jf, true).isValid().should.be.false
  619. })
  620. })
  621. describe('#clone', function() {
  622. it('should return a cloned instance', function() {
  623. var m = moment('1359/2/25', 'jYYYY/jM/jD')
  624. , c = m.clone()
  625. m.add(1, 'jYear')
  626. m.add(5, 'day')
  627. m.format('jYY/jM/jD').should.be.equal('60/2/30')
  628. c.format('jYY/jM/jD').should.be.equal('59/2/25')
  629. })
  630. })
  631. describe('#add', function () {
  632. it('should add gregorian dates correctly', function () {
  633. var gf = 'YYYY-M-D'
  634. , m = moment('1980-5-15', 'YYYY-M-D')
  635. moment(m).add(1, 'day').format(gf).should.be.equal('1980-5-16')
  636. moment(m).add(10, 'days').format(gf).should.be.equal('1980-5-25')
  637. moment(m).add(30, 'days').format(gf).should.be.equal('1980-6-14')
  638. moment(m).add(60, 'days').format(gf).should.be.equal('1980-7-14')
  639. moment(m).add(1, 'month').format(gf).should.be.equal('1980-6-15')
  640. moment(m).add(2, 'months').format(gf).should.be.equal('1980-7-15')
  641. moment(m).add(10, 'months').format(gf).should.be.equal('1981-3-15')
  642. moment(m).add(20, 'months').format(gf).should.be.equal('1982-1-15')
  643. moment(m).add(1, 'year').format(gf).should.be.equal('1981-5-15')
  644. moment(m).add(2, 'years').format(gf).should.be.equal('1982-5-15')
  645. moment(m).add(10, 'years').format(gf).should.be.equal('1990-5-15')
  646. moment(m).add(20, 'years').format(gf).should.be.equal('2000-5-15')
  647. })
  648. it('should add jalaali dates correctly', function () {
  649. var jf = 'jYYYY/jM/jD'
  650. , m = moment('1359/2/25', 'jYYYY/jM/jD')
  651. moment(m).add(1, 'day').format(jf).should.be.equal('1359/2/26')
  652. moment(m).add(4, 'days').format(jf).should.be.equal('1359/2/29')
  653. moment(m).add(10, 'days').format(jf).should.be.equal('1359/3/4')
  654. moment(m).add(30, 'days').format(jf).should.be.equal('1359/3/24')
  655. moment(m).add(60, 'days').format(jf).should.be.equal('1359/4/23')
  656. moment(m).add(365, 'days').format(jf).should.be.equal('1360/2/25')
  657. moment(m).add(1, 'jmonth').format(jf).should.be.equal('1359/3/25')
  658. moment(m).add(2, 'jmonths').format(jf).should.be.equal('1359/4/25')
  659. moment(m).add(10, 'jmonths').format(jf).should.be.equal('1359/12/25')
  660. moment(m).add(20, 'jmonths').format(jf).should.be.equal('1360/10/25')
  661. moment(m).add(1, 'jyear').format(jf).should.be.equal('1360/2/25')
  662. moment(m).add(2, 'jyears').format(jf).should.be.equal('1361/2/25')
  663. moment(m).add(3, 'jyears').format(jf).should.be.equal('1362/2/25')
  664. moment(m).add(4, 'jyears').format(jf).should.be.equal('1363/2/25')
  665. moment(m).add(10, 'jyears').format(jf).should.be.equal('1369/2/25')
  666. moment(m).add(20, 'jyears').format(jf).should.be.equal('1379/2/25')
  667. })
  668. it('should retain last day of month when adding months or years', function () {
  669. var jf = 'jYYYY/jM/jD'
  670. , m = moment('1393/6/31', jf)
  671. moment(m).add(1, 'jmonth').format(jf).should.be.equal('1393/7/30')
  672. moment(m).add(5, 'jmonth').format(jf).should.be.equal('1393/11/30')
  673. moment(m).add(6, 'jmonth').format(jf).should.be.equal('1393/12/29')
  674. m = moment('1391/12/30', jf)
  675. moment(m).add(1, 'jyear').format(jf).should.be.equal('1392/12/29')
  676. moment(m).add(2, 'jyear').format(jf).should.be.equal('1393/12/29')
  677. moment(m).add(3, 'jyear').format(jf).should.be.equal('1394/12/29')
  678. moment(m).add(4, 'jyear').format(jf).should.be.equal('1395/12/30')
  679. })
  680. it('should return invalid moment instance if years is larger than 3177 (add year)', function () {
  681. var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
  682. m.add(1, 'jyear')
  683. m.isValid().should.be.false
  684. m.jYear().should.be.NaN
  685. m.jMonth().should.be.NaN
  686. m.jDate().should.be.NaN
  687. })
  688. it('should return invalid moment instance if years is larger than 3177 (add month)', function () {
  689. var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
  690. m.add(12, 'jmonth')
  691. m.isValid().should.be.false
  692. m.jYear().should.be.NaN
  693. m.jMonth().should.be.NaN
  694. m.jDate().should.be.NaN
  695. })
  696. it('should return invalid moment instance if years is larger than 3177 (add day)', function () {
  697. var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
  698. m.add(365, 'day')
  699. m.isValid().should.be.false
  700. m.jYear().should.be.NaN
  701. m.jMonth().should.be.NaN
  702. m.jDate().should.be.NaN
  703. })
  704. it('should return invalid moment instance if years is larger than 3177 (add seconds)', function () {
  705. var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
  706. m.add(365 * 3600 * 24, 'seconds') // 365 days
  707. m.isValid().should.be.false
  708. m.jYear().should.be.NaN
  709. m.jMonth().should.be.NaN
  710. m.jDate().should.be.NaN
  711. })
  712. })
  713. describe('#subtract', function () {
  714. it('should subtract gregorian dates correctly', function () {
  715. var gf = 'YYYY-M-D'
  716. , m = moment('1980-5-15', 'YYYY-M-D')
  717. moment(m).subtract(1, 'day').format(gf).should.be.equal('1980-5-14')
  718. moment(m).subtract(10, 'days').format(gf).should.be.equal('1980-5-5')
  719. moment(m).subtract(30, 'days').format(gf).should.be.equal('1980-4-15')
  720. moment(m).subtract(60, 'days').format(gf).should.be.equal('1980-3-16')
  721. moment(m).subtract(1, 'month').format(gf).should.be.equal('1980-4-15')
  722. moment(m).subtract(2, 'months').format(gf).should.be.equal('1980-3-15')
  723. moment(m).subtract(10, 'months').format(gf).should.be.equal('1979-7-15')
  724. moment(m).subtract(20, 'months').format(gf).should.be.equal('1978-9-15')
  725. moment(m).subtract(1, 'year').format(gf).should.be.equal('1979-5-15')
  726. moment(m).subtract(2, 'years').format(gf).should.be.equal('1978-5-15')
  727. moment(m).subtract(10, 'years').format(gf).should.be.equal('1970-5-15')
  728. moment(m).subtract(20, 'years').format(gf).should.be.equal('1960-5-15')
  729. })
  730. it('should subtract jalaali dates correctly', function () {
  731. var jf = 'jYYYY/jM/jD'
  732. , m = moment('1359/2/25', 'jYYYY/jM/jD')
  733. moment(m).subtract(1, 'day').format(jf).should.be.equal('1359/2/24')
  734. moment(m).subtract(4, 'days').format(jf).should.be.equal('1359/2/21')
  735. moment(m).subtract(10, 'days').format(jf).should.be.equal('1359/2/15')
  736. moment(m).subtract(30, 'days').format(jf).should.be.equal('1359/1/26')
  737. moment(m).subtract(60, 'days').format(jf).should.be.equal('1358/12/26')
  738. moment(m).subtract(365, 'days').format(jf).should.be.equal('1358/2/26')
  739. moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1359/1/25')
  740. moment(m).subtract(2, 'jmonths').format(jf).should.be.equal('1358/12/25')
  741. moment(m).subtract(10, 'jmonths').format(jf).should.be.equal('1358/4/25')
  742. moment(m).subtract(20, 'jmonths').format(jf).should.be.equal('1357/6/25')
  743. moment(m).subtract(1, 'jyear').format(jf).should.be.equal('1358/2/25')
  744. moment(m).subtract(2, 'jyears').format(jf).should.be.equal('1357/2/25')
  745. moment(m).subtract(3, 'jyears').format(jf).should.be.equal('1356/2/25')
  746. moment(m).subtract(4, 'jyears').format(jf).should.be.equal('1355/2/25')
  747. moment(m).subtract(10, 'jyears').format(jf).should.be.equal('1349/2/25')
  748. moment(m).subtract(20, 'jyears').format(jf).should.be.equal('1339/2/25')
  749. })
  750. it('should retain last day of month when subtracting months or years', function () {
  751. var jf = 'jYYYY/jM/jD'
  752. , m = moment('1393/1/31', jf)
  753. moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/29')
  754. moment(m).subtract(6, 'jmonth').format(jf).should.be.equal('1392/7/30')
  755. moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/31')
  756. m = moment('1391/12/30', jf)
  757. moment(m).subtract(1, 'jyear').format(jf).should.be.equal('1390/12/29')
  758. moment(m).subtract(2, 'jyear').format(jf).should.be.equal('1389/12/29')
  759. moment(m).subtract(3, 'jyear').format(jf).should.be.equal('1388/12/29')
  760. moment(m).subtract(4, 'jyear').format(jf).should.be.equal('1387/12/30')
  761. })
  762. it('should subtract months correctly', function () {
  763. var jf = 'jYYYY/jM/jD'
  764. , m = moment('1393/1/31', jf)
  765. moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/29')
  766. moment(m).subtract(2, 'jmonth').format(jf).should.be.equal('1392/11/30')
  767. moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/31')
  768. moment(m).subtract(12, 'jmonth').format(jf).should.be.equal('1392/1/31')
  769. moment(m).subtract(13, 'jmonth').format(jf).should.be.equal('1391/12/30')
  770. moment(m).subtract(25, 'jmonth').format(jf).should.be.equal('1390/12/29')
  771. m = moment('1393/1/1', jf)
  772. moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/1')
  773. moment(m).subtract(2, 'jmonth').format(jf).should.be.equal('1392/11/1')
  774. moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/1')
  775. moment(m).subtract(12, 'jmonth').format(jf).should.be.equal('1392/1/1')
  776. moment(m).subtract(13, 'jmonth').format(jf).should.be.equal('1391/12/1')
  777. moment(m).subtract(25, 'jmonth').format(jf).should.be.equal('1390/12/1')
  778. m = moment('1393/1/10', jf)
  779. moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/10')
  780. moment(m).subtract(2, 'jmonth').format(jf).should.be.equal('1392/11/10')
  781. moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/10')
  782. moment(m).subtract(12, 'jmonth').format(jf).should.be.equal('1392/1/10')
  783. moment(m).subtract(13, 'jmonth').format(jf).should.be.equal('1391/12/10')
  784. moment(m).subtract(25, 'jmonth').format(jf).should.be.equal('1390/12/10')
  785. })
  786. })
  787. describe('.jIsLeapYear', function() {
  788. it('should return true for Jalaali leap years and false otherwise', function() {
  789. moment.jIsLeapYear(1391).should.be.true
  790. moment.jIsLeapYear(1392).should.be.false
  791. moment.jIsLeapYear(1393).should.be.false
  792. moment.jIsLeapYear(1394).should.be.false
  793. moment.jIsLeapYear(1395).should.be.true
  794. moment.jIsLeapYear(1396).should.be.false
  795. moment.jIsLeapYear(1397).should.be.false
  796. moment.jIsLeapYear(1398).should.be.false
  797. moment.jIsLeapYear(1399).should.be.true
  798. moment.jIsLeapYear(1400).should.be.false
  799. moment.jIsLeapYear(1401).should.be.false
  800. moment.jIsLeapYear(1402).should.be.false
  801. moment.jIsLeapYear(1403).should.be.true
  802. moment.jIsLeapYear(1404).should.be.false
  803. })
  804. })
  805. describe('.loadPersian', function() {
  806. it('should load Persian lang', function() {
  807. var ol = moment.locale()
  808. , m
  809. moment.loadPersian()
  810. m = moment('1980-05-15')
  811. m.format('D MMMM YYYY').should.be.equal('15 مه 1980')
  812. m.format('jD jMMMM jYYYY').should.be.equal('25 اردیبهشت 1359')
  813. m.calendar().should.be.equal('1359/02/25')
  814. m.format('LLLL').should.be.equal('پنج‌شنبه، 25 اردیبهشت 1359 00:00')
  815. m.format('llll').should.be.equal('پنج‌شنبه، 25 ارد 1359 00:00')
  816. moment.locale(ol)
  817. })
  818. })
  819. describe('.loadPersian({usePersianDigits: true})', function() {
  820. it('should load Persian lang with usePersianDigits = true', function() {
  821. var ol = moment.locale()
  822. , m
  823. moment.loadPersian({usePersianDigits: true})
  824. m = moment('1980-05-15')
  825. m.format('D MMMM YYYY').should.be.equal('۱۵ مه ۱۹۸۰')
  826. m.format('jD jMMMM jYYYY').should.be.equal('۲۵ اردیبهشت ۱۳۵۹')
  827. m.calendar().should.be.equal('۱۳۵۹/۰۲/۲۵')
  828. m.format('LLLL').should.be.equal('پنج‌شنبه، ۲۵ اردیبهشت ۱۳۵۹ ۰۰:۰۰')
  829. m.format('llll').should.be.equal('پنج‌شنبه، ۲۵ ارد ۱۳۵۹ ۰۰:۰۰')
  830. moment.locale(ol)
  831. })
  832. })
  833. describe('.loadPersian({dialect: persian-modern})', function() {
  834. it('should load Persian lang with dialect = persian-modern', function() {
  835. var ol = moment.locale()
  836. , m
  837. moment.loadPersian({dialect: 'persian-modern'})
  838. m = moment('1980-05-19')
  839. m.format('D MMMM YYYY').should.be.equal('19 مه 1980')
  840. m.format('jD jMMMM jYYYY').should.be.equal('29 اردیبهشت 1359')
  841. m.calendar().should.be.equal('1359/02/29')
  842. m.format('LLLL').should.be.equal('دوشنبه، 29 اردیبهشت 1359 00:00')
  843. m.format('llll').should.be.equal('دوشنبه، 29 ارد 1359 00:00')
  844. m.format('dd lll').should.be.equal('د 29 ارد 1359 00:00')
  845. moment.locale(ol)
  846. })
  847. })
  848. describe('.unix', function () {
  849. it('should create a moment with unix epoch', function () {
  850. var unix = moment('1359/2/25', 'jYYYY/jM/jD').unix()
  851. moment.unix(unix).format('jYYYY/jM/jD').should.be.equal('1359/2/25')
  852. })
  853. })
  854. describe('#isSame', function () {
  855. it('should work correctly for same year', function () {
  856. var m1 = moment('2016-02-04')
  857. var m2 = moment('2016-01-01')
  858. var m3 = moment('2015-12-31')
  859. var m4 = moment('2017-01-01')
  860. m1.isSame(m2, 'year').should.be.true
  861. m1.isSame(m3, 'year').should.be.false
  862. m1.isSame(m4, 'year').should.be.false
  863. m2.isSame(m3, 'year').should.be.false
  864. m2.isSame(m4, 'year').should.be.false
  865. m3.isSame(m4, 'year').should.be.false
  866. })
  867. it('should work correctly for same month', function () {
  868. var m1 = moment('2016-02-04')
  869. var m2 = moment('2016-02-01')
  870. var m3 = moment('2016-01-01')
  871. var m4 = moment('2016-03-01')
  872. m1.isSame(m2, 'month').should.be.true
  873. m1.isSame(m3, 'month').should.be.false
  874. m1.isSame(m4, 'month').should.be.false
  875. m2.isSame(m3, 'month').should.be.false
  876. m2.isSame(m4, 'month').should.be.false
  877. m3.isSame(m4, 'month').should.be.false
  878. })
  879. it('should work correctly for same day', function () {
  880. var m1 = moment('2016-02-04 06:00')
  881. var m2 = moment('2016-02-04 07:00')
  882. var m3 = moment('2016-02-03 06:00')
  883. var m4 = moment('2016-02-05 06:00')
  884. m1.isSame(m2, 'day').should.be.true
  885. m1.isSame(m3, 'day').should.be.false
  886. m1.isSame(m4, 'day').should.be.false
  887. m2.isSame(m3, 'day').should.be.false
  888. m2.isSame(m4, 'day').should.be.false
  889. m3.isSame(m4, 'day').should.be.false
  890. })
  891. it('should work correctly for same jyear', function () {
  892. var m1 = moment('1394/11/15', 'jYYYY/jMM/jDD')
  893. var m2 = moment('1394/01/01', 'jYYYY/jMM/jDD')
  894. var m3 = moment('1393/11/15', 'jYYYY/jMM/jDD')
  895. var m4 = moment('1395/11/15', 'jYYYY/jMM/jDD')
  896. m1.isSame(m2, 'jyear').should.be.true
  897. m1.isSame(m3, 'jyear').should.be.false
  898. m1.isSame(m4, 'jyear').should.be.false
  899. m2.isSame(m3, 'jyear').should.be.false
  900. m2.isSame(m4, 'jyear').should.be.false
  901. m3.isSame(m4, 'jyear').should.be.false
  902. })
  903. it('should work correctly for same jmonth', function () {
  904. var m1 = moment('1394/11/15', 'jYYYY/jMM/jDD')
  905. var m2 = moment('1394/11/01', 'jYYYY/jMM/jDD')
  906. var m3 = moment('1394/10/15', 'jYYYY/jMM/jDD')
  907. var m4 = moment('1394/12/15', 'jYYYY/jMM/jDD')
  908. m1.isSame(m2, 'jmonth').should.be.true
  909. m1.isSame(m3, 'jmonth').should.be.false
  910. m1.isSame(m4, 'jmonth').should.be.false
  911. m2.isSame(m3, 'jmonth').should.be.false
  912. m2.isSame(m4, 'jmonth').should.be.false
  913. m3.isSame(m4, 'jmonth').should.be.false
  914. })
  915. })
  916. })