export default {
  // Most from Python's strftime:
  // https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
  a: {
    weekday: 'short'
  },
  A: {
    weekday: 'long'
  },
  w: ({
    fmt
  }) => {
    const w = fmt({
      weekday: 'long'
    });
    const lookup = {
      Sunday: 0,
      Monday: 1,
      Tuesday: 2,
      Wednesday: 3,
      Thursday: 4,
      Friday: 5,
      Saturday: 6
    };
    return lookup[w];
  },
  d: {
    day: '2-digit'
  },
  b: {
    month: 'short'
  },
  B: {
    month: 'long'
  },
  m: {
    month: '2-digit'
  },
  y: {
    year: '2-digit'
  },
  Y: {
    year: 'numeric'
  },
  H: {
    hourCycle: 'h23',
    hour: '2-digit'
  },
  I: ({
    fmt
  }) => {
    const h = fmt({
      hourCycle: 'h12',
      hour: '2-digit'
    });
    return h.split(/\s/)[0];
  },
  p: ({
    fmt
  }) => {
    const h = fmt({
      hourCycle: 'h12',
      hour: '2-digit'
    });
    return h.split(/\s/)[1];
  },
  M: ({
    fmt
  }) => {
    const m = fmt({
      minute: '2-digit'
    });
    return m.padStart(2, '0');
  },
  S: ({
    fmt
  }) => {
    const s = fmt({
      second: '2-digit'
    });
    return s.padStart(2, '0');
  },
  Z: ({
    fmt
  }) => {
    const t = fmt({
      minute: 'numeric',
      timeZoneName: 'short'
    });
    return t.split(/\s/)[1];
  },
  // Custom additions
  h: ({
    fmt
  }) => {
    const h = fmt({
      hour: 'numeric'
    });
    return h.split(/\s/)[0];
  },
  D: {
    day: 'numeric'
  },
  Q: ({
    fmt
  }) => {
    const m = fmt({
      month: 'numeric'
    });
    const realMonthToApMonth = {
      1: 'Jan.',
      2: 'Feb.',
      3: 'March',
      4: 'April',
      5: 'May',
      6: 'June',
      7: 'July',
      8: 'Aug.',
      9: 'Sept.',
      10: 'Oct.',
      11: 'Nov.',
      12: 'Dec.'
    };
    return realMonthToApMonth[m];
  },
  P: ({
    fmt
  }) => {
    const h = fmt({
      hourCycle: 'h12',
      hour: '2-digit'
    });
    const ampm = h.split(/\s/)[1];
    const lookup = {
      AM: 'a.m.',
      PM: 'p.m.'
    };
    return lookup[ampm];
  },
  x: {
    month: '2-digit',
    day: '2-digit',
    year: 'numeric'
  },
  hh: ({
    fmt
  }) => {
    const h = fmt({
      hour: '2-digit'
    });
    return h.split(/\s/)[0];
  },
  'h:m': ({
    get
  }) => get('{h}:{M}'),
  'h:m?': ({
    get
  }) => {
    const h = get('{h}');
    const m = get('{M}');
    return m === '00' ? h : `${h}:${m}`;
  },
  'h:m:s': ({
    get
  }) => get('{h}:{M}:{S}'),
  apdate: ({
    get
  }) => get('{Q} {D}, {Y}'),
  aptime: ({
    get
  }) => get('{h:m?} {P} {Z}'),
  aptimefull: ({
    get
  }) => get('{h:m?} {P} {Z}'),
  ap: ({
    get
  }) => get('{apdate}, {aptime}'),
  apfull: ({
    get
  }) => get('{apdate}, {aptimefull}'),
  politicodate: ({
    get
  }) => get('{x}'),
  politicotime: ({
    get
  }) => get('{hh}:{M} {p} {Z}'),
  politico: ({
    get
  }) => get('{politicodate} {politicotime}'),
  iso: ({
    d
  }) => d.toISOString()
};