简体   繁体   中英

Changing the first day of the week in PHP

In my website I am working with timesheets so I have to change the start of the week to any day tat the user wanted to be. By default the start of the week is Sunday or Monday based on the timezone but I might need to have the start of the week as Wednesday. So is there a way to do this in PHP ??

Timesheet Explained

I need to calculate the wages for the people based on the time they are logged in. Now I have to group this wages weekly. When I say weekly the week is not always sunday to saturday it may be wednesday to tuesday or thursday to wednesday. So the week start will be different for different companies.

Say for example an user is logged in for 5 hrs on Monday(19/09/2011) and the same user is logged in for 10 hrs on Wednesday(14/09/2011). And my week starts on Thursday then i get 2 weeks now between those 2 date ranges they are 8/09/2011 to 14/09/2011 and 15/09/2011 to 21/09/2011.

Actually i dont have a code as I could not come up with a logic to establish. I have it in Java but i dont know how to do this in PHP without inbuild functions. Any suggestions ?

The answer I've got for you is not PHP specific, rather it is a suggestion of how you should do it.

What you want is no different to when you must track the months of a fiscal year - the fiscal year can start on any calendar month. The way to do this is to store the day as an offset, ie as a day number.

Thinking about it in an OO way, you may have a data object that represents an actual calendar day (Monday through Sunday), and can hold a real date, so it represents an actual physical day. You then extend this class (inherit from it), and make a class that represents your virtual (or fiscal ) day, and you add an integer property that holds its offset within your virtual/fiscal week.

So your new fiscal day object still represents an absolute date (for example Wednesday 21 October 2011), but it's offset may be zero, signifying that it is the first day in the fiscal week. This is easily extended further so that the fiscal day object can also be aware of its position within a fiscal week and a fiscal month, etc.

I hope that makes sense to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM