import Ember from 'ember';
import moment from 'moment';

const { computed, Logger:logger } = Ember;

export default Ember.Service.extend({
  _timeZone: null,

  locale: null,
  defaultFormat: null,

  init() {
    this._super(...arguments);

    if (!this.get('defaultFormat')) {
      this.set('defaultFormat', 'LLLL');
    }
  },

  timeZone: computed('_timeZone', {
    get() {
      return this.get('_timeZone');
    },

    set(propertyKey, timeZone) {
      if (!moment.tz) {
        logger.warn('[ember-moment] attempted to set timezone, but moment-timezone unavailable.');
        return;
      }

      this.set('_timeZone', timeZone);

      return timeZone;
    }
  }),

  changeLocale(locale) {
    this.set('locale', locale);
  },

  changeTimeZone(timeZone) {
    this.set('timeZone', timeZone);
  },

  moment() {
    let time = moment(...arguments);
    const locale = this.get('locale');
    const timeZone = this.get('timeZone');

    if (locale) {
      time = time.locale(locale);
    }

    if (timeZone && time.tz) {
      time = time.tz(timeZone);
    }

    return time;
  }
});

import Ember from 'ember';
import moment from 'moment';

const { computed, Logger:logger } = Ember;

export default Ember.Service.extend({
  _timeZone: null,

  locale: null,
  defaultFormat: null,

  init() {
    this._super(...arguments);

    if (!this.get('defaultFormat')) {
      this.set('defaultFormat', 'LLLL');
    }
  },

  timeZone: computed('_timeZone', {
    get() {
      return this.get('_timeZone');
    },

    set(propertyKey, timeZone) {
      if (!moment.tz) {
        logger.warn('[ember-moment] attempted to set timezone, but moment-timezone unavailable.');
        return;
      }

      this.set('_timeZone', timeZone);

      return timeZone;
    }
  }),

  changeLocale(locale) {
    this.set('locale', locale);
  },

  changeTimeZone(timeZone) {
    this.set('timeZone', timeZone);
  },
  
  isMoment(obj) {
    return moment.isMoment(obj);
  },

  moment() {
    let time = moment(...arguments);
    const locale = this.get('locale');
    const timeZone = this.get('timeZone');

    if (locale) {
      time = time.locale(locale);
    }

    if (timeZone && time.tz) {
      time = time.tz(timeZone);
    }

    return time;
  }
});

Add a shortcut for isMoment
Add a shortcut for isMoment

Unless I'm seeing it wrong it's harder than it should be to check if an object is a moment object.
The only way I'm able to check it is if I use moment from ``import moment from 'moment'`` in my code alongside importing the service.
I could just use the moment library directly without the service but the service already has the correct timezone.
This added method to the service would be very handy.