(dt: Date | ObjectId, relative = true, format = 'YYYY-M-D H:mm:ss', tz = 'Asia/Shanghai')
| 11 | } |
| 12 | |
| 13 | export function datetimeSpan(dt: Date | ObjectId, relative = true, format = 'YYYY-M-D H:mm:ss', tz = 'Asia/Shanghai') { |
| 14 | if (!dt) return 'DATETIME_SPAN_ERROR'; |
| 15 | if (dt instanceof ObjectId) dt = dt.getTimestamp(); |
| 16 | else if (typeof dt === 'string' && ObjectId.isValid(dt)) dt = new ObjectId(dt).getTimestamp(); |
| 17 | else if (typeof dt === 'number' || typeof dt === 'string') dt = new Date(dt); |
| 18 | return '<span class="time{0}" data-timestamp="{1}">{2}</span>'.format( |
| 19 | relative ? ' relative' : '', |
| 20 | dt.getTime() / 1000, |
| 21 | moment(dt).tz(tz).format(format), |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | export function* paginate(page: number, numPages: number) { |
| 26 | const radius = 5; |
nothing calls this directly
no outgoing calls
no test coverage detected