j'ai eut besoin de retrouver une date en partant sur le nième jour de l'année, alors j'en ai fait une petite application que je vous offre si ça vous intéresse
Code : Tout sélectionner
;DayOfYearToDate
EnableExplicit
Enumeration Fenetres
#Fenetre_principale
EndEnumeration
Enumeration Gadgets
#Txt_Entree
#Str_Entree
#Str_Sortie
#Btn_Valider
#Btn_Quitter
EndEnumeration
Enumeration Polices
#Police
EndEnumeration
Structure sMaMap
Doy.s
Date.s
EndStructure
Global Evenement, Cle.s, Annee = Year(Date()), Mois = Month(Date()), Jour, Resultat$
Global NewMap MaMap.sMaMap(), LngAn
LoadFont(#Police, "Times New Roman", 15, #PB_Font_Bold)
SetGadgetFont(#PB_Default, FontID(#Police))
Macro _AN_BIS(x); cette macro défini si une année x est bissextile ou non
;Auteur PAPIPP http://www.purebasic.fr/french/viewtopic.php?f=6&t=13296
((Bool(Not Bool((x%4)<>0))) & ((1-Bool(Not Bool((x%100)<>0)) ) | Bool(Not Bool(((x>>2)%100)<>0)) ) )
EndMacro
LngAn = 365+_AN_BIS(Annee)
Procedure Quitter()
CloseWindow(#Fenetre_principale)
FreeMap(MaMap())
End
EndProcedure
Procedure Remplir_Map()
Protected m, j, Nbj
;Faire une boucle m de 12 mois
m = 1
While m <= 12
j = 1
Select m
Case 1,3,5,7,8,10,12
Nbj = 31
Case 4, 6, 9, 11
Nbj = 30
Case 2
Nbj = 28 + _AN_BIS(Annee)
EndSelect
;Faire une seconde boucle j avec le nombre de jours pour chaque mois
While j <= Nbj
AddMapElement(MaMap(), Str(DayOfYear(Date(Annee,m,j,0,0,0))))
MaMap()\Doy = Str(DayOfYear(Date(Annee,m,j,0,0,0)))
MaMap()\Date = RSet(Str(j),2,"0")+"/"+RSet(Str(m),2,"0")+"/"+RSet(Str(Annee),4,"0")
j + 1
Wend
m + 1
Wend
EndProcedure
Procedure$ NomJours()
Protected NomJour$ = "Dimanche Lundi Mardi Mercredi Jeudi Vendredi Samedi"
Protected Resultat$ = StringField(NomJour$, Val(Left(MaMap()\Date,2))%7 + 1, " ")
ProcedureReturn Resultat$
EndProcedure
Procedure$ NomMois()
Protected Mois = Val(Mid(MaMap()\Date, 4, 2))
Protected NomMois$ = StringField("Janvier Février Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre", Mois, " ")
ProcedureReturn NomMois$
EndProcedure
Procedure Conversion()
Cle = GetGadgetText(#Str_Entree)
If Val(Cle) < 1 Or Val(Cle) > LngAn
Resultat$ = "Donnée invalide"
Else
FindMapElement(MaMap(), Cle)
Resultat$ = NomJours() + " " + Val(Left(MaMap()\Date,2)) + " " + NomMois() + " " + Annee
EndIf
SetGadgetText(#Str_Sortie, Resultat$)
Cle = ""
EndProcedure
Procedure Programme_principal()
If OpenWindow(#Fenetre_principale, 0, 0, 410, 130, "DatOfYearToDate © Micoute - Août 2018", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_TitleBar)
TextGadget(#Txt_Entree, 10, 10, 320, 30, "Entrez le jour de l'année:", #PB_Text_Center|#SS_CENTERIMAGE)
StringGadget(#Str_Entree, 330, 10, 60, 30, "", #PB_String_BorderLess|#PB_String_Numeric|#ES_CENTER)
ButtonGadget(#Btn_Valider, 250, 50, 100, 30, "Valider")
ButtonGadget(#Btn_Quitter, 50, 50, 100, 30, "Quitter")
StringGadget(#Str_Sortie, 10, 90, 380, 30, "",#SS_CENTERIMAGE|#ES_CENTER)
SetActiveGadget(#Str_Entree)
BindGadgetEvent(#Btn_Valider, @Conversion())
BindGadgetEvent(#Btn_Quitter, @Quitter())
EndIf
EndProcedure
Remplir_Map()
Programme_principal()
;- Boucle principale
Repeat
Evenement = WaitWindowEvent()
Until Evenement = #PB_Event_CloseWindow