Skip to content

Commit

Permalink
fix(monkey): start and end of date range
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Jun 23, 2024
1 parent bf6999b commit ac683fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ export function delay(ms = 2000) {
return new Promise(resolve => setTimeout(resolve, randomMs))
}

export function dayStart(date: Date | number) {
if (typeof date === 'number') {
date = new Date(date)
}
return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()
}
export function dayEnd(date: Date | number) {
if (typeof date === 'number') {
date = new Date(date)
}
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59).getTime()
}

/**
* 可暂停/恢复的循环
* @param fn
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/services/postService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export async function fetchRangePosts(
params: {
uid,
page,
starttime: start / 1000,
endtime: end / 1000,
starttime: dayStart(start) / 1000,
endtime: dayEnd(end) / 1000,
hasori: 1, // 是否包含原创
hasret: hasRepost ? 1 : 0, // 是否包含转发
hastext: 1, // 是否包含文字
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/types/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ declare global {
const createTemplatePromise: typeof import('@vueuse/core')['createTemplatePromise']
const createUnrefFn: typeof import('@vueuse/core')['createUnrefFn']
const customRef: typeof import('vue')['customRef']
const dayEnd: typeof import('../index')['dayEnd']
const dayStart: typeof import('../index')['dayStart']
const debouncedRef: typeof import('@vueuse/core')['debouncedRef']
const debouncedWatch: typeof import('@vueuse/core')['debouncedWatch']
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
Expand Down

0 comments on commit ac683fc

Please sign in to comment.