meridiem.js 421 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const DatePart = require('./datepart');
  3. class Meridiem extends DatePart {
  4. constructor(opts = {}) {
  5. super(opts);
  6. }
  7. up() {
  8. this.date.setHours((this.date.getHours() + 12) % 24);
  9. }
  10. down() {
  11. this.up();
  12. }
  13. toString() {
  14. let meridiem = this.date.getHours() > 12 ? 'pm' : 'am';
  15. return /\A/.test(this.token) ? meridiem.toUpperCase() : meridiem;
  16. }
  17. }
  18. module.exports = Meridiem;