meridiem.js 419 B

123456789101112131415161718192021222324
  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;