{"size": 2914, "ext": "js", "max_stars_repo_path": "WebServer/node_modules/_silly-datetime@0.1.2@silly-datetime/test/test.js", "max_stars_repo_name": "Receiling/ImageRecognition", "max_stars_repo_stars_event_min_datetime": "2015-07-24T08:49:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T06:15:11.000Z", "max_issues_repo_path": "node_modules/silly-datetime/test/test.js", "max_issues_repo_name": "liujunxiang/file_mng_system", "max_issues_repo_issues_event_min_datetime": "2020-07-17T09:08:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T11:59:51.000Z", "max_forks_repo_path": "server/node_modules/silly-datetime/test/test.js", "max_forks_repo_name": "webxiu/kjb-element-admin", "max_forks_repo_forks_event_min_datetime": "2017-03-17T09:54:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T06:15:13.000Z"}
{"max_stars_count": 23, "max_issues_count": 6, "max_forks_count": 4, "avg_line_length": 28.8514851485, "max_line_length": 76, "alphanum_fraction": 0.5562800275}
'use strict';

var assert = require('assert');
var sd = require('../');


describe('silly-datetime', function () {

  describe('#format', function () {
    var FORMAT_A = 'YYYY-MM-DD HH:mm:ss';
    var FORMAT_B = 'M/D/YYYY H:m a';
    var datetime = new Date(2015, 7, 6, 15, 10, 3);
    it('should return as `' + FORMAT_A + '`', function () {
      assert.equal('2015-08-06 15:10:03', sd.format(datetime, FORMAT_A));
    });
    it('should return as `' + FORMAT_B + '`', function () {
      assert.equal('8/6/2015 15:10 pm', sd.format(datetime, FORMAT_B));
    });
  });


  describe('#fromNow', function () {
    var SECOND_IN = 'in a few seconds';
    it('test `' + SECOND_IN + '`', function () {
      var datetime = +new Date() + 3 * 1000;
      assert.equal(SECOND_IN, sd.fromNow(datetime));
    });

    var SECOND_AGO = 'a few seconds ago';
    it('test `' + SECOND_AGO + '`', function () {
      assert.equal(SECOND_AGO, sd.fromNow(NaN));
    });

    var MINUTE = 3;
    var MINUTE_AGO = MINUTE + ' minutes ago';
    it('test `' + MINUTE_AGO + '`', function () {
      var datetime = +new Date() - MINUTE * 60 * 1000;
      assert.equal(MINUTE_AGO, sd.fromNow(datetime));
    });

    var HOUR = 3;
    var HOUR_AGO = HOUR + ' hours ago';
    it('test `' + HOUR_AGO + '`', function () {
      var datetime = +new Date() - HOUR * 60 * 60 * 1000;
      assert.equal(HOUR_AGO, sd.fromNow(datetime));
    });


    var DAY = 3;
    var DAY_AGO = DAY + ' days ago';
    it('test `' + DAY_AGO + '`', function () {
      var datetime = +new Date() - DAY * 24 * 60 * 60 * 1000;
      assert.equal(DAY_AGO, sd.fromNow(datetime));
    });


    var MONTH = 3;
    var MONTH_AGO = MONTH + ' months ago';
    it('test `' + MONTH_AGO + '`', function () {
      var datetime = new Date();
      datetime.setMonth(datetime.getMonth() - MONTH);
      assert.equal(MONTH_AGO, sd.fromNow(datetime));
    });

    var YEAR = 3;
    var YEAR_AGO = YEAR + ' years ago';
    it('test `' + YEAR_AGO + '`', function () {
      var datetime = new Date();
      datetime.setFullYear(datetime.getFullYear() - YEAR);
      assert.equal(YEAR_AGO, sd.fromNow(datetime));
    });
  });


  describe('#locate', function () {
    var FORMAT_ZH_CN_MINUTE = 10;
    var FORMAT_ZH_CN = FORMAT_ZH_CN_MINUTE + '分钟内';
    it('should return as `' + FORMAT_ZH_CN + '`', function () {
      var datetime = +new Date() + (FORMAT_ZH_CN_MINUTE * 60 + 1) * 1000;
      sd.locate('zh-cn');
      assert.equal(
        FORMAT_ZH_CN,
        sd.fromNow(datetime)
      );
    });

    var FORMAT_ZH_TW_HOUR = 10;
    var FORMAT_ZH_TW = FORMAT_ZH_TW_HOUR + '小時以内';
    it('should return as `' + FORMAT_ZH_TW + '`', function () {
      var datetime = +new Date() + (FORMAT_ZH_TW_HOUR * 60 * 60 + 1) * 1000;
      sd.locate({ future: '%s以内', hh: '%s小時' });
      assert.equal(
        FORMAT_ZH_TW,
        sd.fromNow(datetime)
      );
    });
  });


});
