luxon -> date-fns
This commit is contained in:
+25
-25
@@ -1,14 +1,14 @@
|
||||
import $ from 'jquery';
|
||||
import Popper from 'popper.js';
|
||||
(window as unknown as {Popper:unknown}).Popper = Popper;//XXX: 왜 popper를 이렇게 불러야 하는가?
|
||||
(window as unknown as { Popper: unknown }).Popper = Popper;//XXX: 왜 popper를 이렇게 불러야 하는가?
|
||||
import 'bootstrap';
|
||||
import { DateTime } from 'luxon';
|
||||
import download from 'downloadjs';
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { isInteger } from 'lodash';
|
||||
import { combineArray, errUnknown, getNpcColor, isBrightColor, numberWithCommas } from './common_legacy';
|
||||
import { unwrap_any } from './util/unwrap_any';
|
||||
import { BasicGeneralListResponse, InvalidResponse } from './defs';
|
||||
import { formatTime } from './util/formatTime';
|
||||
|
||||
type CityAttackerInfo = {
|
||||
level: number,
|
||||
@@ -73,7 +73,7 @@ type GeneralInfo = {
|
||||
|
||||
type BattleInfo = {
|
||||
attackerGeneral: GeneralInfo,
|
||||
attackerCity: CityAttackerInfo|CityBasicInfo,
|
||||
attackerCity: CityAttackerInfo | CityBasicInfo,
|
||||
attackerNation: NationBasicInfo,
|
||||
defenderGenerals: GeneralInfo[],
|
||||
defenderCity: CityBasicInfo,
|
||||
@@ -95,24 +95,24 @@ type ExportedBattleInfo = {
|
||||
type ExportedInfo = ExportedGeneralInfo | ExportedBattleInfo;
|
||||
|
||||
type BattleResult = {
|
||||
result:true,
|
||||
datetime:string,
|
||||
lastWarLog:{
|
||||
generalBattleResultLog: string,
|
||||
generalBattleDetailLog: string,
|
||||
},
|
||||
avgWar:number,
|
||||
phase:number,
|
||||
killed:number,
|
||||
maxKilled:number,
|
||||
minKilled:number,
|
||||
dead:number,
|
||||
maxDead:number,
|
||||
minDead:number,
|
||||
attackerRice:number,
|
||||
defenderRice:number,
|
||||
attackerSkills:Record<string, number>,
|
||||
defendersSkills:Record<string, number>[],
|
||||
result: true,
|
||||
datetime: string,
|
||||
lastWarLog: {
|
||||
generalBattleResultLog: string,
|
||||
generalBattleDetailLog: string,
|
||||
},
|
||||
avgWar: number,
|
||||
phase: number,
|
||||
killed: number,
|
||||
maxKilled: number,
|
||||
minKilled: number,
|
||||
dead: number,
|
||||
maxDead: number,
|
||||
minDead: number,
|
||||
attackerRice: number,
|
||||
defenderRice: number,
|
||||
attackerSkills: Record<string, number>,
|
||||
defendersSkills: Record<string, number>[],
|
||||
}
|
||||
|
||||
declare global {
|
||||
@@ -254,7 +254,7 @@ $(function ($) {
|
||||
|
||||
$('.btn-battle-save').on('click', function () {
|
||||
const battleData = exportAllData();
|
||||
const dateText = DateTime.now().toFormat('yyyyMMdd_HHmmss');
|
||||
const dateText = formatTime(new Date(), 'yyyyMMdd_HHmmss');
|
||||
const filename = `battle_${dateText}.json`;
|
||||
const saveData = JSON.stringify({
|
||||
objType: 'battle',
|
||||
@@ -973,7 +973,7 @@ $(function ($) {
|
||||
|
||||
generalList.sort(function (lhs, rhs) {
|
||||
if (lhs.npc != rhs.npc) {
|
||||
return (lhs.npc??0) - (rhs.npc??0);
|
||||
return (lhs.npc ?? 0) - (rhs.npc ?? 0);
|
||||
}
|
||||
if (lhs.name < rhs.name) {
|
||||
return -1;
|
||||
@@ -987,7 +987,7 @@ $(function ($) {
|
||||
$optGroup.css('background-color', color);
|
||||
$optGroup.css('color', isBrightColor(color) ? 'black' : 'white');
|
||||
|
||||
for(const general of generalList){
|
||||
for (const general of generalList) {
|
||||
const $item = $(`<option value="${general.no}">${general.name}</option>`);
|
||||
if (general.npc) {
|
||||
$item.css('color', unwrap(getNpcColor(general.npc)));
|
||||
@@ -1005,7 +1005,7 @@ $(function ($) {
|
||||
data: {
|
||||
req: 2,
|
||||
}
|
||||
}).then(function (data: BasicGeneralListResponse|InvalidResponse) {
|
||||
}).then(function (data: BasicGeneralListResponse | InvalidResponse) {
|
||||
if (!data.result) {
|
||||
alert(data.reason);
|
||||
$('#importModal').modal('hide');
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import axios from 'axios';
|
||||
import $ from 'jquery';
|
||||
import { range } from 'lodash';
|
||||
import { DateTime } from 'luxon';
|
||||
import { addMinutes } from 'date-fns';
|
||||
import { errUnknown, getNpcColor } from './common_legacy';
|
||||
import { InvalidResponse } from './defs';
|
||||
import { unwrap } from "./util/unwrap";
|
||||
import { convertFormData } from './util/convertFormData';
|
||||
import { unwrap_any } from "./util/unwrap_any";
|
||||
import { parseTime } from './util/parseTime';
|
||||
import { formatTime } from './util/formatTime';
|
||||
|
||||
declare const maxChiefTurn: number;
|
||||
|
||||
@@ -132,16 +134,16 @@ async function reloadTable() {
|
||||
|
||||
plateObj.officerLevelText.text(chiefInfo.officerLevelText);
|
||||
|
||||
let turnTimeObj: DateTime|undefined;
|
||||
let turnTimeObj: Date|undefined;
|
||||
|
||||
if (chiefInfo.turnTime) {
|
||||
turnTimeObj = DateTime.fromSQL(chiefInfo.turnTime);
|
||||
turnTimeObj = parseTime(chiefInfo.turnTime);
|
||||
}
|
||||
|
||||
const turnList = plateObj.turn;
|
||||
$.each(chiefInfo.turn, function (turnIdx, turnText) {
|
||||
if (turnTimeObj) {
|
||||
turnList[turnIdx].turnTime.text(turnTimeObj.toFormat('HH:mm'));
|
||||
turnList[turnIdx].turnTime.text(formatTime(turnTimeObj, 'HH:mm'));
|
||||
}
|
||||
else {
|
||||
turnList[turnIdx].turnTime.text('');
|
||||
@@ -155,7 +157,7 @@ async function reloadTable() {
|
||||
turnList[turnIdx].turnText.css('font-size', '{0}px'.format(newFontSize));
|
||||
}
|
||||
if (turnTimeObj) {
|
||||
turnTimeObj = turnTimeObj.plus({'minutes': turnTerm});
|
||||
turnTimeObj = addMinutes(turnTimeObj, turnTerm);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { format, formatISO9075 } from 'date-fns';
|
||||
//const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
|
||||
const DATE_TIME_FORMAT_WITH_FRACTION = 'yyyy-MM-dd HH:mm:ss.SSS';
|
||||
|
||||
export function formatTime(time: Date, withFraction?:boolean): string;
|
||||
export function formatTime(time: Date, format:string): string;
|
||||
|
||||
export function formatTime(time: Date, withFractionOrFormat:string|boolean = false): string {
|
||||
if (typeof withFractionOrFormat === "string") {
|
||||
return format(time, withFractionOrFormat);
|
||||
}
|
||||
else if(withFractionOrFormat){
|
||||
return format(time, DATE_TIME_FORMAT_WITH_FRACTION);
|
||||
}
|
||||
else {
|
||||
return formatISO9075(time);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,4 @@
|
||||
import {DateTime} from 'luxon';
|
||||
|
||||
export const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
|
||||
export const DATE_TIME_FORMAT_WITH_FRACTION = 'yyyy-MM-dd HH:mm:ss.SSS';
|
||||
|
||||
export function getDateTimeNow(withFraction = false): string{
|
||||
if(withFraction){
|
||||
return DateTime.now().toFormat(DATE_TIME_FORMAT_WITH_FRACTION);
|
||||
}
|
||||
else{
|
||||
return DateTime.now().toFormat(DATE_TIME_FORMAT);
|
||||
}
|
||||
|
||||
import { formatTime } from './formatTime';
|
||||
export function getDateTimeNow(withFraction = false): string {
|
||||
return formatTime(new Date(), withFraction);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import {parseISO} from 'date-fns';
|
||||
|
||||
export function parseTime(dateString: string): Date{
|
||||
return parseISO(dateString);
|
||||
}
|
||||
+2
-3
@@ -23,11 +23,11 @@
|
||||
"axios": "^0.21.1",
|
||||
"bootstrap": "^4.6.0",
|
||||
"core-js": "^3.16.2",
|
||||
"date-fns": "^2.23.0",
|
||||
"downloadjs": "^1.4.7",
|
||||
"jquery": "^3.6.0",
|
||||
"js-sha512": "^0.8.0",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^2.0.2",
|
||||
"select2": "^4.0",
|
||||
"vue": "^3.2.2"
|
||||
},
|
||||
@@ -39,7 +39,6 @@
|
||||
"@types/bootstrap": "^4.6.1",
|
||||
"@types/jquery": "^3.5.6",
|
||||
"@types/lodash": "^4.14.172",
|
||||
"@types/luxon": "^2.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
||||
"@typescript-eslint/parser": "^4.29.2",
|
||||
"@vue/compiler-sfc": "^3.2.2",
|
||||
@@ -63,4 +62,4 @@
|
||||
"pre-commit": [
|
||||
"lint"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -1,15 +1,17 @@
|
||||
import { setAxiosXMLHttpRequest } from "../hwe/ts/util/setAxiosXMLHttpRequest";
|
||||
import $ from 'jquery';
|
||||
import Popper from 'popper.js';
|
||||
(window as unknown as {Popper:unknown}).Popper = Popper;//XXX: 왜 popper를 이렇게 불러야 하는가?
|
||||
(window as unknown as { Popper: unknown }).Popper = Popper;//XXX: 왜 popper를 이렇게 불러야 하는가?
|
||||
import 'bootstrap';
|
||||
import axios from 'axios';
|
||||
import { DateTime } from "luxon";
|
||||
import { DATE_TIME_FORMAT, getDateTimeNow } from "../hwe/ts/util/getDateTimeNow";
|
||||
import { subDays } from 'date-fns';
|
||||
import { getDateTimeNow } from "../hwe/ts/util/getDateTimeNow";
|
||||
import { sha512 } from "js-sha512";
|
||||
import { convertFormData } from "../hwe/ts/util/convertFormData";
|
||||
import { InvalidResponse } from "../hwe/ts/defs";
|
||||
import { unwrap } from "../hwe/ts/util/unwrap";
|
||||
import { parseTime } from "../hwe/ts/util/parseTime";
|
||||
import { formatTime } from "../hwe/ts/util/formatTime";
|
||||
|
||||
type ResultUserInfo = {
|
||||
result: true,
|
||||
@@ -295,7 +297,7 @@ async function deleteMe() {
|
||||
|
||||
async function extendAuth() {
|
||||
const validUntil = $('#slot_token_valid_until').html();
|
||||
const availableAt = DateTime.fromFormat(validUntil, DATE_TIME_FORMAT).minus({ days: 5 }).toFormat(DATE_TIME_FORMAT);
|
||||
const availableAt = formatTime(subDays(parseTime(validUntil), 5));
|
||||
const now = getDateTimeNow();
|
||||
|
||||
if (now < availableAt) {
|
||||
@@ -321,7 +323,7 @@ async function extendAuth() {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!result.result){
|
||||
if (!result.result) {
|
||||
alert(result.reason);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user