"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.timeFormat = exports.showWeekLastDay = exports.showWeekFirstDay = exports.showNextWeekFirstDay = exports.showNextMonthFirstDay = exports.showMonthLastDay = exports.showMonthFirstDay = exports.getTimeString = exports.getNextDayOfYear = exports.getFirstDayOfYear = exports["default"] = void 0;

var _constant = require("./constant");

var _getLocale = require("./getLocale");

var getTimeString = function getTimeString(time, nowTime) {
  if (!time) {
    return (0, _getLocale.getLocale)("OKR_MyO_KRP_Notupdated");
  }

  var months = (0, _constant.getMonth)();
  var timeDateObj = new Date(time);
  var timeMilliSecond = timeDateObj.getTime();
  var timeYear = timeDateObj.getFullYear();
  var timeMonth = timeDateObj.getMonth() + 1;
  var timeDate = timeDateObj.getDate();
  var timeHours = timeDateObj.getHours();
  var timeMinutes = timeDateObj.getMinutes();
  var nowMilliSecond = nowTime.getTime();
  var nowYear = nowTime.getFullYear();
  var nowDate = nowTime.getDate();
  var secondDiff = Math.floor((nowMilliSecond - timeMilliSecond) / 1000);

  if (secondDiff <= 3) {
    return (0, _getLocale.getLocale)("Pro_page_Int_Justnow");
  }

  if (secondDiff < 60) {
    return "".concat(secondDiff).concat((0, _getLocale.getLocale)("Mood_secago"));
  }

  if (secondDiff < 60 * 60) {
    return "".concat(Math.floor(secondDiff / 60)).concat((0, _getLocale.getLocale)("Tasks_Tab_MyS_minuteago"));
  }

  if (secondDiff < 60 * 60 * 24) {
    return "".concat(Math.floor(secondDiff / (60 * 60))).concat((0, _getLocale.getLocale)("Mood_hoursago"));
  }

  if (secondDiff < 60 * 60 * 24 * 2 && nowDate - 1 === timeDate) {
    return "".concat((0, _getLocale.getLocale)("OKR_MyO_Pr_Text_Yesterday"), " ", "".concat(timeHours < 10 ? "0".concat(timeHours) : timeHours, ":").concat(timeMinutes < 10 ? "0".concat(timeMinutes) : timeMinutes));
  }

  if (secondDiff < 60 * 60 * 24 * 3 && nowDate - 2 === timeDate) {
    return "".concat((0, _getLocale.getLocale)("Mood_2daysago"), " ", "".concat(timeHours < 10 ? "0".concat(timeHours) : timeHours, ":").concat(timeMinutes < 10 ? "0".concat(timeMinutes) : timeMinutes));
  }

  if (timeYear === nowYear) {
    var _dateStr = months[timeMonth - 1] + (_getLocale.isEn ? " ".concat(timeDate, " ") : "".concat(timeDate, "\u65E5"));

    return "".concat(_dateStr, " ").concat(timeHours < 10 ? "0".concat(timeHours) : timeHours, ":").concat(timeMinutes < 10 ? "0".concat(timeMinutes) : timeMinutes);
  }

  var dateStr = (_getLocale.isEn ? "" : "".concat(timeYear, "\u5E74")) + months[timeMonth - 1] + (_getLocale.isEn ? " ".concat(timeDate, " ") : "".concat(timeDate, "\u65E5")) + (_getLocale.isEn ? ",".concat(timeYear) : "");
  return "".concat(dateStr, " ").concat(timeHours < 10 ? "0".concat(timeHours) : timeHours, ":").concat(timeMinutes < 10 ? "0".concat(timeMinutes) : timeMinutes);
}; // 日期格式化，返回值形式为yy-mm-dd


exports.getTimeString = getTimeString;

var timeFormat = function timeFormat(NowDate) {
  var date = new Date(NowDate);
  var y = date.getFullYear(); // 年

  var m = date.getMonth() + 1; // 月

  var d = date.getDate(); // 日

  return "".concat(y, "/").concat(m, "/").concat(d, " 0:0:0");
}; // 获取当年第一天


exports.timeFormat = timeFormat;

var getFirstDayOfYear = function getFirstDayOfYear() {
  var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Date();
  date.setDate(1);
  date.setMonth(0);
  return timeFormat(date);
}; // 获取明年第一天


exports.getFirstDayOfYear = getFirstDayOfYear;

var getNextDayOfYear = function getNextDayOfYear() {
  var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Date();
  date.setFullYear(date.getFullYear() + 1);
  return getFirstDayOfYear(date);
}; // 本周第一天


exports.getNextDayOfYear = getNextDayOfYear;

var showWeekFirstDay = function showWeekFirstDay() {
  var Nowdate = new Date();
  var weekDay = Nowdate.getDay() || 7; // @ts-ignore

  var WeekFirstDay = new Date(Nowdate - (weekDay - 1) * 86400000);
  var M = Number(WeekFirstDay.getMonth()) + 1;
  return "".concat(WeekFirstDay.getFullYear(), "/").concat(M, "/").concat(WeekFirstDay.getDate(), " 0:0:0");
}; // 本周最后一天


exports.showWeekFirstDay = showWeekFirstDay;

var showWeekLastDay = function showWeekLastDay() {
  var Nowdate = new Date();
  var weekDay = Nowdate.getDay() || 7; // @ts-ignore

  var WeekFirstDay = new Date(Nowdate - (weekDay - 1) * 86400000); // @ts-ignore

  var WeekLastDay = new Date((WeekFirstDay / 1000 + 6 * 86400) * 1000);
  var M = Number(WeekLastDay.getMonth()) + 1;
  return "".concat(WeekLastDay.getFullYear(), "/").concat(M, "/").concat(WeekLastDay.getDate());
}; // 下周第一天


exports.showWeekLastDay = showWeekLastDay;

var showNextWeekFirstDay = function showNextWeekFirstDay() {
  var Nowdate = new Date();
  var weekDay = Nowdate.getDay() || 7; // @ts-ignore

  var WeekFirstDay = new Date(Nowdate - (weekDay - 1) * 86400000); // @ts-ignore

  var WeekLastDay = new Date((WeekFirstDay / 1000 + 7 * 86400) * 1000);
  var M = Number(WeekLastDay.getMonth()) + 1;
  return "".concat(WeekLastDay.getFullYear(), "/").concat(M, "/").concat(WeekLastDay.getDate(), " 0:0:0");
}; // 本月第一天


exports.showNextWeekFirstDay = showNextWeekFirstDay;

var showMonthFirstDay = function showMonthFirstDay() {
  var Nowdate = new Date();
  var MonthFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth(), 1);
  var M = Number(MonthFirstDay.getMonth()) + 1;
  return "".concat(MonthFirstDay.getFullYear(), "/").concat(M, "/").concat(MonthFirstDay.getDate(), " 0:0:0");
}; // 本月最后一天


exports.showMonthFirstDay = showMonthFirstDay;

var showMonthLastDay = function showMonthLastDay() {
  var Nowdate = new Date();
  var MonthNextFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth() + 1, 1); // @ts-ignore

  var MonthLastDay = new Date(MonthNextFirstDay - 86400000);
  var M = Number(MonthLastDay.getMonth()) + 1;
  return "".concat(MonthLastDay.getFullYear(), "/").concat(M, "/").concat(MonthLastDay.getDate());
}; // 下个月第一天


exports.showMonthLastDay = showMonthLastDay;

var showNextMonthFirstDay = function showNextMonthFirstDay() {
  var Nowdate = new Date();
  var MonthFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth() + 1, 1);
  var M = Number(MonthFirstDay.getMonth()) + 1;
  return "".concat(MonthFirstDay.getFullYear(), "/").concat(M, "/").concat(MonthFirstDay.getDate(), " 0:0:0");
};

exports.showNextMonthFirstDay = showNextMonthFirstDay;
var _default = {
  getTimeString: getTimeString,
  timeFormat: timeFormat,
  showWeekFirstDay: showWeekFirstDay,
  showMonthFirstDay: showMonthFirstDay,
  showNextWeekFirstDay: showNextWeekFirstDay,
  showNextMonthFirstDay: showNextMonthFirstDay
};
exports["default"] = _default;