Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
How to check that current time is between working hours

I need to check if the current time is between a representative's work hours (not with external library as momentJS).

What I have:

localTimeZone = 'America/New_York';
localWorkingHours = [
  {day: 'Sunday', from: '08:00', to: '14:00'},
  {day: 'Sunday', from: '23:00', to: '23:59'},
  {day: 'Monday', from: '00:00', to: '07:00'},
  {day: 'Tuesday', from: '08:00', to: '16:00'},
  {day: 'Wednesday', from: '08:00', to: '16:00'}
];

const now = new Date();
const currentDayInWeek = now.toLocaleString("en-US", {
    timeZone: localTimeZone,
    weekday: 'long'
});
const workingTimes = localWorkingHours.filter(times => times.day === currentDayInWeek);
workingTimes.forEach((time) => {
   // what is the best option to check that current time is between time.from and time.to ?
   // note that this code should run in another AWS region.
})
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I did this:

const now = new Date();
const currentDayInWeek = now.toLocaleString("en-US", {
    timeZone: localTimeZone,
    weekday: 'long'
});
const currentTime = new Intl.DateTimeFormat([], {
    timeZone: localTimeZone,
    hour12: false,
    hour: '2-digit',
    minute: '2-digit'
}).format(now);

const workingTimes = localWorkingHours.filter(times => times.day === currentDayInWeek);

return workingTimes.some((time) => {
    if (currentTime >= time.from && currentTime <= time.to) return true;
});
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda