All files / src/zones fixedOffsetZone.js

91.67% Statements 22/24
81.25% Branches 13/16
90.91% Functions 10/11
91.67% Lines 22/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71      32x               207x 10x   207x       98x       2x 2x 2x 2x             57x 57x       208x       4x 4x 4x 4x 4x   4x               210x       1326x       246x       658x      
import { Util } from '../impl/util';
import { Zone } from '../zone';
 
let singleton = null;
 
/**
 * @private
 */
 
export class FixedOffsetZone extends Zone {
  static get utcInstance() {
    if (singleton === null) {
      singleton = new FixedOffsetZone(0);
    }
    return singleton;
  }
 
  static instance(offset) {
    return offset === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset);
  }
 
  static parseSpecifier(s) {
    Eif (s) {
      const r = s.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);
      Eif (r) {
        return new FixedOffsetZone(Util.signedOffset(r[1], r[2]));
      }
    }
    return null;
  }
 
  constructor(offset) {
    super();
    this.fixed = offset;
  }
 
  get type() {
    return 'fixed';
  }
 
  get name() {
    const hours = this.fixed / 60,
      minutes = Math.abs(this.fixed % 60),
      sign = hours > 0 ? '+' : '-',
      base = sign + Math.abs(hours),
      number = minutes > 0 ? `${base}:${Util.pad(minutes, 2)}` : base;
 
    return this.fixed === 0 ? 'UTC' : `UTC${number}`;
  }
 
  offsetName() {
    return this.name();
  }
 
  get universal() {
    return true;
  }
 
  offset() {
    return this.fixed;
  }
 
  equals(otherZone) {
    return otherZone.type === 'fixed' && otherZone.fixed === this.fixed;
  }
 
  get isValid() {
    return true;
  }
}