ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Re: Date/jour/semaine   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

ven. 20 décembre 2013, 14h24
Gregory Adam
Belgique Belgique

atoutfox.public.association

Re: Date/jour/semaine


Je crois que le lundi de la semaine 201401 est le 30/12/2013

[VFP]
&& _jpb_date
*_______________________________________________________________________________
#include "FoxPro.h"
#define true .t.
#define false .f.
*_______________________________________________________________________________
function _jpb_date()

local yyyyww, datefrom, dateto
yyyyww = '201401'
?ISOyyyywwToDateFromDateTo(m.yyyyww , @datefrom, @dateto)
?yyyyww , datefrom, dateto

endfunc
*_______________________________________________________________________________
function ISOyyyywwToDateFromDateTo( yyyyww, dateFrom, dateTo)

local success
success = true

local yearId, weekId, jan1

do case
case !m.success

case !IsChar(m.yyyyww, true)
assert false
success = false

case !inlist(len(m.yyyyww), 6)
assert false
success = false

case !AllDigits(m.yyyyww)
assert false
success = false

case !between(right(m.yyyyww, 2), '01', '53')
assert false
success = false

otherwise
yearId = int(val(left(m.yyyyww, 4)))
weekId = int(val(right(m.yyyyww, 2)))

endcase
#if false
take yyyyy first monday
advance # of weeks (ww - 1)
calc the sunday
#endif

local jan1Monday, jan1Mondayyyyyww, weeksToAdd

do case
case !m.success

otherwise
jan1Monday = ToFirstDayOfWeek(date(m.yearId, 1, 1), 1)

jan1Mondayyyyyww = DateToISOyyyyww(m.jan1Monday)
weeksToAdd = m.weekId - int(val(right(m.jan1Mondayyyyyww, 2)))

#if false
the first monday of a year is always week 01 or week 02

if( left(m.jan1Mondayyyyyww, 4) < left(m.yyyyww, 4) )
weeksToAdd = m.weekId
assert false


endif
#endif

dateFrom = m.jan1Monday + 7 * m.weeksToAdd
dateTo = m.dateFrom + 6

endcase
do case
case !m.success

case DateToISOyyyyww(m.dateFrom) == m.yyyyww
&& ok

otherwise
&& yyyywww does not exist
success = false

endcase
return m.success

endfunc
*________________________________________________________________________________

function DateToISOyyyyww(d)

if( !inlist(month(m.d) , 1, 12) )
return padl((year(m.d)) * 100 + week(m.d, 2, 2), 6, '0')
endif

if( (month(m.d) == 1) and (week(m.d, 2, 2) >= 52) )
return padl((year(m.d)-1) * 100 + week(m.d, 2, 2), 6, '0')
endif

if( (month(m.d) == 12) and (week(m.d, 2, 2) == 1) )
return padl((year(m.d)+1) * 100 + week(m.d, 2, 2), 6, '0')
endif

return padl((year(m.d)) * 100 + week(m.d, 2, 2), 6, '0')

endfunc
*________________________________________________________________________________
#if false
goes to first mon, tue including or following a date
if the date is already that weekday - the same date is returned
#endif
function ToFirstDayOfWeek(d, weekday)

do case
case !IsDate(m.d, true)
error 11, 'd'

case !IsInteger(m.weekday) or !between(m.weekday, 1, 7)
error 11, 'weekday'

otherwise
return m.d + mod( 7 + m.weekday - dow(m.d, 2), 7)
endcase

endfunc
*________________________________________________________________________________
function IsChar(s, needFilled)

return inlist(vartype(m.s), T_CHARACTER, T_MEMO, T_VARCHAR, T_VARBINARY, T_BLOB) ;
and iif(m.needFilled, !empty(len(m.s)), true)

endfunc
*_______________________________________________________________________________
function IsInteger(n)

return inlist(vartype(m.n), T_NUMERIC, T_DOUBLE, T_INTEGER, T_CURRENCY) ;
and empty(mod(m.n, 1))

endfunc
*_______________________________________________________________________________
function IsDate(s, needFilled)

return inlist(vartype(m.s), T_DATE) ;
and iif(m.needFilled, !empty(m.s), true)
endfunc
*_______________________________________________________________________________
function AllDigits(s)

return IsChar(@m.s) and empty(len(chrtran(m.s, '01213456789', '')))
endfunc
*_______________________________________________________________________________
[/VFP}

Permalink : http://www.atoutfox.org/nntp.asp?ID=0000013464
20 286 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2026.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3