refactor: improve date handling and timezone consistency
- Add timezone support to database module (+08:00) - Extract date formatting utilities to shared modules - Standardize timezone handling across frontend and backend - Improve date formatting consistency in UI components - Refactor crawler page.goto options for better readability
This commit is contained in:
@@ -3,6 +3,11 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, LessThan } from 'typeorm';
|
||||
import { BidItem } from '../entities/bid-item.entity';
|
||||
import { CrawlInfoAdd } from '../../crawler/entities/crawl-info-add.entity';
|
||||
import {
|
||||
getDaysAgo,
|
||||
setStartOfDay,
|
||||
setEndOfDay,
|
||||
} from '../../common/utils/timezone.util';
|
||||
|
||||
interface FindAllQuery {
|
||||
page?: number;
|
||||
@@ -73,8 +78,7 @@ export class BidsService {
|
||||
}
|
||||
|
||||
async cleanOldData() {
|
||||
const thirtyDaysAgo = new Date();
|
||||
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
||||
const thirtyDaysAgo = getDaysAgo(30);
|
||||
return this.bidRepository.delete({
|
||||
createdAt: LessThan(thirtyDaysAgo),
|
||||
});
|
||||
@@ -91,9 +95,7 @@ export class BidsService {
|
||||
}
|
||||
|
||||
async getRecentBids() {
|
||||
const thirtyDaysAgo = new Date();
|
||||
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
||||
thirtyDaysAgo.setHours(0, 0, 0, 0);
|
||||
const thirtyDaysAgo = setStartOfDay(getDaysAgo(30));
|
||||
|
||||
return this.bidRepository
|
||||
.createQueryBuilder('bid')
|
||||
@@ -118,14 +120,12 @@ export class BidsService {
|
||||
const qb = this.bidRepository.createQueryBuilder('bid');
|
||||
|
||||
if (startDate) {
|
||||
const start = new Date(startDate);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
const start = setStartOfDay(new Date(startDate));
|
||||
qb.andWhere('bid.publishDate >= :startDate', { startDate: start });
|
||||
}
|
||||
|
||||
if (endDate) {
|
||||
const end = new Date(endDate);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
const end = setEndOfDay(new Date(endDate));
|
||||
qb.andWhere('bid.publishDate <= :endDate', { endDate: end });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user