Python : Vérifier si une date est le premier jour de la semaine avec UliEngineering

Vous pouvez facilement vérifier si des valeurs datetime correspondent au premier jour de la semaine (lundi) en utilisant la bibliothèque Python UliEngineering :

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

# Vérifier des dates individuelles
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')}")

# Vérifier un tableau NumPy datetime64
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}")

Exemple de sortie

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]

La fonction is_first_day_of_week() fonctionne à la fois avec des dates individuelles et des tableaux NumPy datetime64, renvoyant un tableau booléen pour les entrées de type tableau.

Articles liés


Check out similar posts by category: Python, NumPy