80 lines
3.2 KiB
TypeScript
80 lines
3.2 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import { dateUtils } from '../src/dateUtils';
|
|
|
|
describe('dateUtils', () => {
|
|
describe('isTradingDay', () => {
|
|
it('should return true for weekdays (Monday-Friday)', () => {
|
|
// Monday (June 2, 2025)
|
|
expect(dateUtils.isTradingDay(new Date(2025, 5, 2))).toBe(true);
|
|
// Tuesday (June 3, 2025)
|
|
expect(dateUtils.isTradingDay(new Date(2025, 5, 3))).toBe(true);
|
|
// Wednesday (June 4, 2025)
|
|
expect(dateUtils.isTradingDay(new Date(2025, 5, 4))).toBe(true);
|
|
// Thursday (June 5, 2025)
|
|
expect(dateUtils.isTradingDay(new Date(2025, 5, 5))).toBe(true);
|
|
// Friday (June 6, 2025)
|
|
expect(dateUtils.isTradingDay(new Date(2025, 5, 6))).toBe(true);
|
|
});
|
|
|
|
it('should return false for weekends (Saturday-Sunday)', () => {
|
|
// Saturday (June 7, 2025)
|
|
expect(dateUtils.isTradingDay(new Date(2025, 5, 7))).toBe(false);
|
|
// Sunday (June 8, 2025)
|
|
expect(dateUtils.isTradingDay(new Date(2025, 5, 8))).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('getNextTradingDay', () => {
|
|
it('should return the next day when current day is a weekday and next day is a weekday', () => {
|
|
// Monday -> Tuesday
|
|
const monday = new Date(2025, 5, 2);
|
|
const tuesday = new Date(2025, 5, 3);
|
|
expect(dateUtils.getNextTradingDay(monday).toDateString()).toBe(tuesday.toDateString());
|
|
});
|
|
|
|
it('should skip weekends when getting next trading day', () => {
|
|
// Friday -> Monday
|
|
const friday = new Date(2025, 5, 6);
|
|
const monday = new Date(2025, 5, 9);
|
|
expect(dateUtils.getNextTradingDay(friday).toDateString()).toBe(monday.toDateString());
|
|
});
|
|
|
|
it('should handle weekends as input correctly', () => {
|
|
// Saturday -> Monday
|
|
const saturday = new Date(2025, 5, 7);
|
|
const monday = new Date(2025, 5, 9);
|
|
expect(dateUtils.getNextTradingDay(saturday).toDateString()).toBe(monday.toDateString());
|
|
|
|
// Sunday -> Monday
|
|
const sunday = new Date(2025, 5, 8);
|
|
expect(dateUtils.getNextTradingDay(sunday).toDateString()).toBe(monday.toDateString());
|
|
});
|
|
});
|
|
|
|
describe('getPreviousTradingDay', () => {
|
|
it('should return the previous day when current day is a weekday and previous day is a weekday', () => {
|
|
// Tuesday -> Monday
|
|
const tuesday = new Date(2025, 5, 3);
|
|
const monday = new Date(2025, 5, 2);
|
|
expect(dateUtils.getPreviousTradingDay(tuesday).toDateString()).toBe(monday.toDateString());
|
|
});
|
|
|
|
it('should skip weekends when getting previous trading day', () => {
|
|
// Monday -> Friday
|
|
const monday = new Date(2025, 5, 9);
|
|
const friday = new Date(2025, 5, 6);
|
|
expect(dateUtils.getPreviousTradingDay(monday).toDateString()).toBe(friday.toDateString());
|
|
});
|
|
|
|
it('should handle weekends as input correctly', () => {
|
|
// Saturday -> Friday
|
|
const saturday = new Date(2025, 5, 7);
|
|
const friday = new Date(2025, 5, 6);
|
|
expect(dateUtils.getPreviousTradingDay(saturday).toDateString()).toBe(friday.toDateString());
|
|
|
|
// Sunday -> Friday
|
|
const sunday = new Date(2025, 5, 8);
|
|
expect(dateUtils.getPreviousTradingDay(sunday).toDateString()).toBe(friday.toDateString());
|
|
});
|
|
});
|
|
});
|