Skip to content

Instantly share code, notes, and snippets.

@adejorosam
Created October 8, 2024 10:22
Show Gist options
  • Save adejorosam/fb67b6e10cd867fa5df612f6aa9db904 to your computer and use it in GitHub Desktop.
Save adejorosam/fb67b6e10cd867fa5df612f6aa9db904 to your computer and use it in GitHub Desktop.
import { Injectable } from '@nestjs/common';
import * as moment from 'moment-timezone';
isMarketOpen(): boolean {
// Define Lagos market hours
const marketOpen = { start: '10:00', end: '14:30' }; // 10 AM to 2:30 PM
// Get current time in Lagos
const lagosTime = moment().tz('Africa/Lagos');
// Check if today is a weekend (Saturday = 6, Sunday = 0)
const isWeekend = lagosTime.day() === 6 || lagosTime.day() === 0;
if (isWeekend) {
return false;
}
// Check if current time is within Lagos market hours
const isLagosMarketOpen = lagosTime.format('HH:mm') >= lagosMarketOpen.start && lagosTime.format('HH:mm') <= lagosMarketOpen.end;
return isLagosMarketOpen;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment