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