DayOfWeek() bug ou pas ?

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

DayOfWeek() bug ou pas ?

Message par Backup »

voila je voulais faire un petit prg qui me dis quel jour je suis né
je sais de source sur, que c'est un Mardi

alors j'ai fait ce petit code :

Code : Tout sélectionner

x= DayOfWeek(Date(2010,12,04,12,00,00))

semaine$="Dimanche,Lundi,Mardi,Mercredi,Jeudi,Vendredi,Samedi"
x=x+1 ; stringfield() commence a 1 , alors que DayofWeek() commence a 0
Debug StringField(semaine$,x,",")

mais ça bug Grave ! ; ça renvoi pas la bonne réponse !!
ça marche pour Aujourd'hui

mais pas pour ma date de naissance (Année 1964)

pouvez vous tester avec votre date de naissance , si vous connaissez le jour
et me dire, si ce code fonctionne avec la votre ? :)
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: DayOfWeek() bug ou pas ?

Message par Ar-S »

La bibliothèque Date permet de gérer le temps et les dates depuis 1970 jusqu'à 2038, en utilisant le modèle Unix (nombre de secondes écoulées depuis le 1er janvier 1970).
T'es trop vieux mon pote :)

Code : Tout sélectionner

	x= DayOfWeek(Date(1975,11,14,10,14,00)) 
	semaine$="Dimanche,Lundi,Mardi,Mercredi,Jeudi,Vendredi,Samedi" 
	x=x+1 ; stringfield() commence a 1 , alors que DayofWeek() commence a 0 
	Debug StringField(semaine$,x,",") 
Je suis né un mardi, il se plante aussi.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
case
Messages : 1546
Inscription : lun. 10/sept./2007 11:13

Re: DayOfWeek() bug ou pas ?

Message par case »

14 novembre 1975 était semble t-il un vendredi, je dis ca, je dis rien ...

petite recherche sur google pour avoir un journal de l'époque ..

http://www.infos-edipro.org/Dochml/pres ... qdp034.jpg
ImageImage
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: DayOfWeek() bug ou pas ?

Message par Ar-S »

oh ba mince alors, moi qui était persuadé du mardi :)
Comme quoi ça doit bien venir de la limitation à 1970 alors..
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: DayOfWeek() bug ou pas ?

Message par Backup »

mince , j'avais pas vu cette limitation de 1970 :roll: (j'me d'mande pourquoi..cette limitation. :) )
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: DayOfWeek() bug ou pas ?

Message par Ar-S »

j'avais appris le pourquoi en 2001 lors d'une formation en technicien de maintenance système/réseau et prog..
J'ai oublié depuis :oops:
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
case
Messages : 1546
Inscription : lun. 10/sept./2007 11:13

Re: DayOfWeek() bug ou pas ?

Message par case »

c'est pas nowel mais bon ...


la limite viens du fait que la date est calculée avec le nombre de secondes écoulées depuis janvier 1970... c'est noté dans l'index date de la doc pb

Code : Tout sélectionner

Declare isbisextile(year)
Declare.s getday(year,month,day)
Debug getday(1975,11,14)
Procedure.s getday(year,month,day)
  key$="1,4,4,0,2,5,0,3,6,1,4,6"
  day$="Samedi,Dimanche,Lundi,Mardi,Mercredi,Jeudi,Vendredi"
  ;-----------------------------
  last2=Val(Right(Str(year),2))
  douzaines=last2/12
  reste=last2-(douzaines*12)
  resultat=(day+(((douzaines+reste+(reste/4)) % 7)+Val(StringField(key$,month,","))))%7
  If isbisextile(year) And month<=2
    resultat -1
  EndIf
  Select Left(Str(Year),2)
    Case "18"
      resultat+2
    Case "20"
      resultat-1
  EndSelect
  ProcedureReturn StringField(day$,resultat+1,",")
EndProcedure
Procedure isbisextile(year)
  If (year/4)*4=year
    If (Year/100)*100<>year
      ProcedureReturn 1
    EndIf    
  EndIf
  If (Year/400)*400=year
    ProcedureReturn 1
  EndIf
  ProcedureReturn 0
EndProcedure
ImageImage
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: DayOfWeek() bug ou pas ?

Message par Backup »

Merci pour ton code :)
il fonctionne nickel , meme pour 1964 ! :)
Parole De JOJO
Messages : 446
Inscription : mar. 25/mai/2010 17:24
Localisation : Bnei Brak, Israel

Re: DayOfWeek() bug ou pas ?

Message par Parole De JOJO »

j'ai ecris un code pour traduire des dates, calendrier hebraique et normal, pour 6000 ans.
si ca interresse quelqun, je peux le poster, ca affiche aussi le jour de la semaine
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: DayOfWeek() bug ou pas ?

Message par Backup »

Parole De JOJO a écrit :j'ai ecris un code pour traduire des dates, calendrier hebraique
ça dois etre tres spécifique 8O
Parole De JOJO
Messages : 446
Inscription : mar. 25/mai/2010 17:24
Localisation : Bnei Brak, Israel

Re: DayOfWeek() bug ou pas ?

Message par Parole De JOJO »

specifique?
je ne sais pas
en tout cas ca donne le jour de la semaine, et c'etait un sacre boulot
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: DayOfWeek() bug ou pas ?

Message par Ar-S »

Je suis curieux de voir ça moi, je suis preneur JOJO
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Parole De JOJO
Messages : 446
Inscription : mar. 25/mai/2010 17:24
Localisation : Bnei Brak, Israel

Re: DayOfWeek() bug ou pas ?

Message par Parole De JOJO »

bon c'est assez complique, je l'ai extrait d'un programme donc ce n'est pas tres clair

voila le main

Code : Tout sélectionner

Enumeration
  #window_0  ; Window
  #jn:#mn:#yn:#jj:#mj:#yj  ;  Combo
  #Text_DOW
EndEnumeration
Global NewList moij.s()
Global Dim tmoi.s(12,2)
Global Dim twik.s(7,2)
Global Dim tadr.s(2,2)
Global ymin=1900,yscl=200
Define.l:Global k,jn,mn,yn,jj,mj,yj
Define.d:Global jd
IncludeFile "proced.pb"
texte():liste():OpenWindow_Window_0()
filldate()
jh=procdates(0)
HideWindow(#window_0,0)
jh=procdates(1)
SetGadgetText(#Text_DOW,week(jh-1))

Repeat
  yhe=WaitWindowEvent()
  gad=EventGadget()
  wev=WindowEvent()
  Select gad 
    Case #jn,#mn,#yn:jh=procdates(1)
    Case #jj,#mj,#yj:jh=procdates(2)
  EndSelect
  adar(jh)
  Select yhe
    Case #PB_Event_CloseWindow:qit=1
  EndSelect
Until qit=1
End
et l'include

Code : Tout sélectionner

Procedure.d FPart(x.d):If x=>0:ProcedureReturn x-Int(x):EndIf
If x<0:ProcedureReturn x+Int(x):EndIf:EndProcedure
Procedure.d Rnd(x.d,y):ProcedureReturn Int(x*Pow(10,y))/Pow(10,y):EndProcedure
Procedure.d Mod(x.d,y):a.d=rnd(x-Int(x/y)*y,5)
If a<0:a+y:EndIf:ProcedureReturn a:EndProcedure

Procedure.s Str0(x):a.s="":If x<10:a="0":EndIf
ProcedureReturn a+Str(x):EndProcedure

Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 352, 167, 600, 50, "", #PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_SystemMenu|#PB_Window_Invisible)
    If CreateGadgetList(WindowID(#Window_0))
      ComboBoxGadget(#jn, 10, 10, 50, 30)
      ComboBoxGadget(#mn, 70, 10, 100, 30)
      ComboBoxGadget(#yn, 180, 10, 80, 30)
      ComboBoxGadget(#jj, 545, 10, 50, 30)
      ComboBoxGadget(#mj, 440, 10, 95, 30)
      ComboBoxGadget(#yj, 350, 10, 80, 30)
      TextGadget(#Text_DOW, 270, 10, 70, 20, "")
    EndIf
  EndIf
EndProcedure

Procedure texte()
  
  tmoi(1,2)="January"
  tmoi(2,2)="February"
  tmoi(3,2)="March"
  tmoi(4,2)="April"
  tmoi(5,2)="May"
  tmoi(6,2)="June"
  tmoi(7,2)="July"
  tmoi(8,2)="August"
  tmoi(9,2)="September"
  tmoi(10,2)="October"
  tmoi(11,2)="November"
  tmoi(12,2)="December"
  
  tadr(1,2)="Adar"
  tadr(2,2)="Adar 2"
  
  twik(1,2)="Sunday"
  twik(2,2)="Monday"
  twik(3,2)="Tuesday"
  twik(4,2)="Wednesday"
  twik(5,2)="Thursday"
  twik(6,2)="Friday"
  twik(7,2)="Saturday"
EndProcedure

Procedure liste()
  AddElement(moij()):moij()="Tishri"
  AddElement(moij()):moij()="Heshvan"
  AddElement(moij()):moij()="Kislev"
  AddElement(moij()):moij()="Tevet"
  AddElement(moij()):moij()="Shevat"
  AddElement(moij()):moij()="Adar"
  AddElement(moij()):moij()="Nissan"
  AddElement(moij()):moij()="Iyar"
  AddElement(moij()):moij()="Sivan"
  AddElement(moij()):moij()="Tamouz"
  AddElement(moij()):moij()="Av"
  AddElement(moij()):moij()="Eloul"
EndProcedure



;-Dates
Procedure.s week(jd)
  ProcedureReturn twik(Int(mod(jd+1.5,7)+1),2)
EndProcedure

Procedure jhtn(jh)
  If jh>1951163
    f=Int((jh-1519219.25)/36524.25)
    a=JH+1+F-Int(f/4)+347997
  EndIf
  If jh<1951164
    a=jh+347997
  EndIf
  b=a+1524
  c=Int((B-122.1)/365.25)
  d=Int(365.25*C)
  e=Int((b-d)/30.6001)
  If e>13
    jn=b-d-Int(30.6001*E)
    mn=e-13
    yn=c-4715
  EndIf
  If e<14
    jn=b-d-Int(30.6001*E)
    mn=e-1
    yn=c-4716
  EndIf
EndProcedure

Procedure tnjh()
  x=0
  g=0
  b.d=0
  f.d=0
  mmn=mn
  ynn=yn
  If mmn<3
    ynn-1
    mmn+12
  EndIf
  If ynn+mmn/100+jn/10000>1582.1004
    a.d=Int(ynn/100)
    b=2-a+Int(a/4)
  EndIf
  If ynn<0
    f=0.75
  EndIf
  jh.d=Int(365.25*ynn-f)+Int(30.6001*(mmn+1))+jn+1372998+b
  ProcedureReturn jh
EndProcedure
  
Procedure jhti(jh)
  a=Int((25920*jh)/765433)
  yj=Int((19*a+252)/235)
  c=mod(12*yj+17,19)
  a=Int((1+235*(yj-1))/19)
  b=(765433*a+63924)/25920
  d.d=b-Int(b/7)*7
  If Int(d)=1 Or Int(d)=4 Or Int(d)=6
    x=1
  EndIf
  If Int(d)=3 And d>=7847/2160 And c<12
    x=2
  EndIf
  If Int(d)=2 And d>=75109/25920 And c>4 And c<12
    x=1
  EndIf
  e.d=Int((1+235*yj)/19)
  f.d=(765433*e+63924)/25920
  p.d=f-Int(f/7)*7
  If Int(p)=1 Or Int(p)=4 Or Int(p)=6
    g=1
  EndIf
  If Int(p)=3 And p>=7847/2160 And c>6
    g=2
  EndIf
  If Int(p)=2 And p>=75109/25920 And c>11
    g=1
  EndIf
  w=Int(f)+g-Int(b)-x
  h=Int(b)+x-2
  v=jh-h
  
  If v<1
    jj=29+v
    mj=12
    yj-1
    c=mod(12*yj+17,19)
    
  EndIf
  If v<1 And c>11
    mj=13
  EndIf
  If v>0
    If w=383 Or w=353
      z=v+Int((v+291)/380)
    EndIf
    If w=384 Or w=354
      z=v
    EndIf
    If w=385 Or w=355
      z=v-Int((v+319)/380)
    EndIf
    
    If w<380
      mj=Int((z+28.5)/29.5)
      jj=z-Int(29.5*mj)+29
    EndIf
    If w>380
      mj=Int((z+28.5-0.5*Int((z+232)/380))/29.5)
      jj=z-Int(29.5*mj)+29-Int(fpart((0.5*mj)*Int((mj+5)/12))+0.5)
    EndIf
    If v=60 And w=355
      mj=2
      jj=30
    EndIf
    If v=60 And w=385
      mj=2
      jj=30
    EndIf
  EndIf
EndProcedure

Procedure tijh()
  x=0
  g=0
  c.l=mod(12*yj+17,19)
  a=Int((1+235*(yj-1))/19)
  b=(765433*a+63924)/25920
  d=b-Int(b/7)*7
  If Int(d)=1 Or Int(d)=4 Or Int(d)=6
    x=1
  ElseIf Int(d)=3 And d>=7847/2160 And c<12
    x=2
  ElseIf Int(d)=2 And d>=75109/25920 And c>4 And c<12
    x=1
  EndIf
  e.d=Int((1+235*yj)/19)
  f.d=(765433*e+63924)/25920
  p.d=f-Int(f/7)*7
  If Int(p)=1 Or Int(p)=4 Or Int(p)=6
    g=1
  ElseIf Int(p)=3 And p>=7847/2160 And c>6
    g=2
  ElseIf Int(p)=2 And p>=75109/25920 And c>11
    g=1
  EndIf
  w=Int(f)+g-Int(b)-x
  h=Int(b)+x-2
  
  Select w
    Case 353,383
      z=Int(29.5*mj)-29+jj-Int((mj+8)/12)
    Case 354,384
      z=Int(29.5*mj)-29+jj
    Case 355,385
      z=Int(29.5*mj)-29+jj+Int((mj+9)/12)
  EndSelect
  If w<380
    v=z
  ElseIf w>380
    v=z+Int(fpart(0.5*mj*Int((mj+5)/12))+0.5)
  EndIf
  jh=h+v
  ProcedureReturn jh
EndProcedure


Procedure FillDate()
  For k=1 To 12
    AddGadgetItem(#mn,-1,tmoi(k,2))
  Next
  For k=0 To 11
    SelectElement(moij(), k)
    AddGadgetItem(#mj,-1,moij())
  Next
  For k=1 To 31
    AddGadgetItem(#jn,-1,Str(k))
  Next
  For k=ymin To ymin+yscl
    AddGadgetItem(#yn,-1,Str(k))
  Next
  
  For k=ymin+3760 To ymin+3760+yscl
    AddGadgetItem(#yj,-1,Str(k))
  Next
  For k=1 To 30
    AddGadgetItem(#jj,-1,Str(k))
  Next
  
  SetGadgetState(#jn,jn)
  SetGadgetState(#mn,mn)
  SetGadgetState(#yn,yn)
EndProcedure

Procedure procdates(flag)
  If flag=0
    jn=Val(FormatDate("%dd",Date()))
    mn=Val(FormatDate("%mm",Date()))
    yn=Val(FormatDate("%yyyy",Date()))
    jh=tnjh():jhti(jh)
    SetGadgetState(#jn,jn-1)
    SetGadgetState(#mn,mn-1)
    SetGadgetState(#yn,yn-ymin)
    SetGadgetState(#jj,jj-1)
    SetGadgetState(#mj,mj-1)
    SetGadgetState(#yj,yj-ymin-3760)
  ElseIf flag=1
    jn=GetGadgetState(#jn)+1
    mn=GetGadgetState(#mn)+1
    yn=GetGadgetState(#yn)+ymin
    jh=tnjh():jhti(jh)
    SetGadgetState(#jj,jj-1)
    SetGadgetState(#mj,mj-1)
    SetGadgetState(#yj,yj-ymin-3760)
  ElseIf flag=2
    jj=GetGadgetState(#jj)+1
    mj=GetGadgetState(#mj)+1
    yj=GetGadgetState(#yj)+ymin+3760
    jh=tijh():jhtn(jh)
    SetGadgetState(#jn,jn-1)
    SetGadgetState(#mn,mn-1)
    SetGadgetState(#yn,yn-ymin)
  EndIf
  SetGadgetText(#Text_DOW,week(jd))
  ProcedureReturn jh
EndProcedure

Procedure adar(jh)
  c.l=Mod(12*yj+17,19)
  If c>11 And GetGadgetItemText(#mj,12)=""
    AddGadgetItem(#mj,6,tadr(2,2))
  EndIf
  If c<12 And GetGadgetItemText(#mj,12)<>"" And GetGadgetItemText(#mj,6)=tadr(2,2)
    RemoveGadgetItem(#mj,6)
  EndIf
  jd=jh+347996.5
  If GetGadgetText(#mj)=""
    SetGadgetText(#mj,tadr(1,2))
  EndIf
EndProcedure
ce qui est bien est que aussi pour les dates juliennes ca marche (avant 1582)
Parole De JOJO
Messages : 446
Inscription : mar. 25/mai/2010 17:24
Localisation : Bnei Brak, Israel

Re: DayOfWeek() bug ou pas ?

Message par Parole De JOJO »

Parole De JOJO a écrit :

Code : Tout sélectionner

Global ymin=1900,yscl=200
ici regler l'annee de depart et le nombre d'annee a afficher
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

Re: DayOfWeek() bug ou pas ?

Message par kernadec »

Bonjour
merci, JOjO
Mais il y a un peut être un souci car le 9 décembre 1582 est un dimanche julien comme le dit wiki :http://fr.wikipedia.org/wiki/Calendrier_perp%C3%A9tuel
au sujet du calendrier français et dans ton code donne un Jeudi?


Cordialement
Répondre