Como verificar se datetime é primeiro dia da semana em Python usando UliEngineering

Você pode verificar facilmente se valores datetime são o primeiro dia da semana (segunda-feira) usando a biblioteca Python UliEngineering:

is_first_day_of_week.py
import numpy as np
from UliEngineering.Utils.Date import *

# Verificar datas individuais
print(f"Is 2024-01-01 first of week? {is_first_day_of_week('2024-01-01')}")
print(f"Is 2024-01-08 first of week? {is_first_day_of_week('2024-01-08')}")

# Verificar array datetime64 do NumPy
dates = np.array(['2024-01-01', '2024-01-02', '2024-01-08', '2024-01-09'], dtype='datetime64[D]')
result = is_first_day_of_week(dates)
print(f"\nFirst of week check: {result}")

Exemplo de saída

is_first_day_of_week_output.txt
Is 2024-01-01 first of week? True
Is 2024-01-08 first of week? True

First of week check: [ True False  True False]

A função is_first_day_of_week() funciona tanto com datas individuais quanto com arrays datetime64 do NumPy, retornando um array booleano para entradas de array.

Posts relacionados


Check out similar posts by category: Python, NumPy