日期计算改为utc
This commit is contained in:
parent
bedb3792e1
commit
6d45922010
@ -1,7 +1,7 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"chain": 5611,
|
"chain": 5611,
|
||||||
"fromBlock": 25594195,
|
"fromBlock": 25776083,
|
||||||
"filters": [{
|
"filters": [{
|
||||||
"key": "input",
|
"key": "input",
|
||||||
"op": "eq",
|
"op": "eq",
|
||||||
@ -17,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"chain": 5611,
|
"chain": 5611,
|
||||||
"fromBlock": 25594195,
|
"fromBlock": 25776083,
|
||||||
"filters": [{
|
"filters": [{
|
||||||
"key": "input",
|
"key": "input",
|
||||||
"op": "like",
|
"op": "like",
|
||||||
@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"chain": 5611,
|
"chain": 5611,
|
||||||
"fromBlock": 25594195,
|
"fromBlock": 25776083,
|
||||||
"filters": [{
|
"filters": [{
|
||||||
"key": "input",
|
"key": "input",
|
||||||
"op": "like",
|
"op": "like",
|
||||||
@ -49,7 +49,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"chain": 5611,
|
"chain": 5611,
|
||||||
"fromBlock": 25594195,
|
"fromBlock": 25776083,
|
||||||
"filters": [{
|
"filters": [{
|
||||||
"key": "input",
|
"key": "input",
|
||||||
"op": "like",
|
"op": "like",
|
||||||
@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"chain": 5611,
|
"chain": 5611,
|
||||||
"fromBlock": 25594195,
|
"fromBlock": 25776083,
|
||||||
"filters": [{
|
"filters": [{
|
||||||
"key": "input",
|
"key": "input",
|
||||||
"op": "like",
|
"op": "like",
|
||||||
|
22
scription_release.json
Normal file
22
scription_release.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"apps": [
|
||||||
|
{
|
||||||
|
"name": "chain-scription",
|
||||||
|
"script": "npm",
|
||||||
|
"args": "run prod:scription",
|
||||||
|
"cwd": "/home/kingsome/code/web_chain_client",
|
||||||
|
"max_memory_restart": "1024M",
|
||||||
|
"log_date_format": "YYYY-MM-DD HH:mm Z",
|
||||||
|
"watch": false,
|
||||||
|
"ignore_watch": ["node_modules", "logs", "fixtures", "tasks"],
|
||||||
|
"instances": 1,
|
||||||
|
"exec_mode": "fork",
|
||||||
|
"env": {
|
||||||
|
"NODE_ENV": "production"
|
||||||
|
},
|
||||||
|
"env_production": {
|
||||||
|
"NODE_ENV": "production"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import { CheckIn } from 'models/CheckIn'
|
import { CheckIn } from 'models/CheckIn'
|
||||||
import { NftHolder } from 'models/NftHolder'
|
import { NftHolder } from 'models/NftHolder'
|
||||||
import { BaseController, role, router, ZError } from 'zutils'
|
import { BaseController, role, router, ZError } from 'zutils'
|
||||||
import { getMonthBegin, getNDayAgo } from 'zutils/utils/date.util'
|
import { getMonthBegin, getNDayAgo } from 'utils/utcdate.util'
|
||||||
|
|
||||||
class TaskController extends BaseController {
|
class TaskController extends BaseController {
|
||||||
@role('anon')
|
@role('anon')
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { getModelForClass, index, modelOptions, prop } from '@typegoose/typegoose'
|
import { getModelForClass, index, modelOptions, prop } from '@typegoose/typegoose'
|
||||||
import { dbconn } from 'decorators/dbconn'
|
import { dbconn } from 'decorators/dbconn'
|
||||||
import { BaseModule } from './Base'
|
import { BaseModule } from './Base'
|
||||||
import { formatDate, yesterday } from 'zutils/utils/date.util'
|
// import { formatDate, yesterday } from 'zutils/utils/date.util'
|
||||||
|
import { formatDate, yesterday } from 'utils/utcdate.util'
|
||||||
import logger from 'logger/logger'
|
import logger from 'logger/logger'
|
||||||
|
|
||||||
@dbconn()
|
@dbconn()
|
||||||
|
@ -5,7 +5,7 @@ import logger from 'logger/logger'
|
|||||||
|
|
||||||
import { getPastBlocksIter } from 'utils/block.util'
|
import { getPastBlocksIter } from 'utils/block.util'
|
||||||
import { ZRedisClient } from 'zutils'
|
import { ZRedisClient } from 'zutils'
|
||||||
import { formatDate } from 'zutils/utils/date.util'
|
import { formatDate } from 'utils/utcdate.util'
|
||||||
|
|
||||||
export class BlockSyncSvr {
|
export class BlockSyncSvr {
|
||||||
chainCfg: IChain
|
chainCfg: IChain
|
||||||
|
55
src/utils/utcdate.util.ts
Normal file
55
src/utils/utcdate.util.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
export const ONE_DAY = 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
|
// format the date to the format we want
|
||||||
|
export const formatDate = (date: Date): string => {
|
||||||
|
const year = date.getUTCFullYear()
|
||||||
|
const month = (date.getUTCMonth() + 1 + '').padStart(2, '0')
|
||||||
|
const day = (date.getUTCDate() + '').padStart(2, '0')
|
||||||
|
return `${year}${month}${day}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// get formated datestring of yesterday
|
||||||
|
export const yesterday = (date?: Date) => {
|
||||||
|
date = date || new Date()
|
||||||
|
date.setUTCDate(date.getUTCDate() - 1)
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
||||||
|
export const nextday = (date?: Date) => {
|
||||||
|
date = date || new Date()
|
||||||
|
date.setUTCDate(date.getUTCDate() + 1)
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
||||||
|
// calc days between two Date
|
||||||
|
export function daysBetween(date1: Date, date2: Date) {
|
||||||
|
// hours*minutes*seconds*milliseconds
|
||||||
|
const diffInMs = Math.abs(date1.getTime() - date2.getTime())
|
||||||
|
const diffInDays = Math.round(diffInMs / ONE_DAY)
|
||||||
|
return diffInDays
|
||||||
|
}
|
||||||
|
|
||||||
|
// get begin of one day
|
||||||
|
export const getDayBegin = (date: Date): Date => {
|
||||||
|
const year = date.getUTCFullYear()
|
||||||
|
const month = date.getUTCMonth()
|
||||||
|
const day = date.getUTCDate()
|
||||||
|
return new Date(year, month, day)
|
||||||
|
}
|
||||||
|
|
||||||
|
// get begin of n day ago
|
||||||
|
export const getNDayAgo = (n: number, begin: boolean): Date => {
|
||||||
|
const date = new Date(Date.now() - n * ONE_DAY)
|
||||||
|
if (begin) {
|
||||||
|
return getDayBegin(date)
|
||||||
|
} else {
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get begin of this month
|
||||||
|
export const getMonthBegin = (date: Date): Date => {
|
||||||
|
const year = date.getUTCFullYear()
|
||||||
|
const month = date.getUTCMonth()
|
||||||
|
return new Date(year, month, 1)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user