logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

date_utils.spec.js (1589B)


  1. import * as DateUtils from 'src/services/date_utils/date_utils.js'
  2. describe('DateUtils', () => {
  3. describe('relativeTime', () => {
  4. it('returns now with low enough amount of seconds', () => {
  5. const futureTime = Date.now() + 20 * DateUtils.SECOND
  6. const pastTime = Date.now() - 20 * DateUtils.SECOND
  7. expect(DateUtils.relativeTime(futureTime, 30)).to.eql({ num: 0, key: 'time.now' })
  8. expect(DateUtils.relativeTime(pastTime, 30)).to.eql({ num: 0, key: 'time.now' })
  9. })
  10. it('rounds down for past', () => {
  11. const time = Date.now() - 1.8 * DateUtils.HOUR
  12. expect(DateUtils.relativeTime(time)).to.eql({ num: 1, key: 'time.unit.hours' })
  13. })
  14. it('rounds up for future', () => {
  15. const time = Date.now() + 1.8 * DateUtils.HOUR
  16. expect(DateUtils.relativeTime(time)).to.eql({ num: 2, key: 'time.unit.hours' })
  17. })
  18. it('uses plural when necessary', () => {
  19. const time = Date.now() - 3.8 * DateUtils.WEEK
  20. expect(DateUtils.relativeTime(time)).to.eql({ num: 3, key: 'time.unit.weeks' })
  21. })
  22. it('works with date string', () => {
  23. const time = Date.now() - 4 * DateUtils.MONTH
  24. const dateString = new Date(time).toISOString()
  25. expect(DateUtils.relativeTime(dateString)).to.eql({ num: 4, key: 'time.unit.months' })
  26. })
  27. })
  28. describe('relativeTimeShort', () => {
  29. it('returns the short version of the same relative time', () => {
  30. const time = Date.now() + 2 * DateUtils.YEAR
  31. expect(DateUtils.relativeTimeShort(time)).to.eql({ num: 2, key: 'time.unit.years_short' })
  32. })
  33. })
  34. })