time2min.mjs

  1. import ot from 'dayjs'
  2. import istime from './istime.mjs'
  3. /**
  4. * 秒時間取至分時間
  5. *
  6. * Unit Test: {@link https://github.com/yuda-lyu/wsemi/blob/master/test/time2min.test.mjs Github}
  7. * @memberOf wsemi
  8. * @param {String} t 輸入秒時間字串,不含時區
  9. * @returns {String} 回傳分時間字串
  10. * @example
  11. *
  12. * console.log(time2min('2019-01-01T12:34:56'))
  13. * // => '2019-01-01T12:34'
  14. *
  15. */
  16. function time2min(t) {
  17. //check
  18. if (!istime(t)) {
  19. return ''
  20. }
  21. let d = ot(t, 'YYYY-MM-DDTHH:mm:ss')
  22. let r = d.format('YYYY-MM-DDTHH:mm')
  23. return r
  24. }
  25. export default time2min