In fact, to be accurate to the week, that is, given the current time, know is the term of the first few weeks of school. The crux of the problem seems to be the lack of regularity, I am using the following code (PHP), the accuracy is not good enough:
function teachweek ($date){ $timestamp=strtotime($date); if (date('m', $timestamp)>=9){ return date('W', $timestamp)-35; }elseif(date('m', $timestamp)<=2){ return date('W', $timestamp)+18; }else{ return date('W', $timestamp)-7; }}
Reply content:
In fact, to be accurate to the week, that is, given the current time, know is the term of the first few weeks of school. The crux of the problem seems to be the lack of regularity, I am using the following code (PHP), the accuracy is not good enough:
function teachweek ($date){ $timestamp=strtotime($date); if (date('m', $timestamp)>=9){ return date('W', $timestamp)-35; }elseif(date('m', $timestamp)<=2){ return date('W', $timestamp)+18; }else{ return date('W', $timestamp)-7; }}
The problem of inaccuracy should be 35, 18 of these numbers, in addition, if September 1 is Saturday or Sunday, it is not counted as the first week, so you can first determine the year of September 1 is in the week
$thisyear=date('Y',strtotime($date));$ondate=date('W',strtotime("1 September $thisyear"));
In this way, line fourth can be replaced with
return date('W', $timestamp)-$ondate+1;
Whether the +1 needs to be determined by the judgement of whether the September 1 is Saturday/day, this is not written here specifically;
If the date is before the beginning of the winter holiday, you also need to calculate the number of weeks of the year from September 1 to December 31
$lastyear=date('Y',strtotime($date))-1;$lastyearweeks=date('W',strtotime("31 December $lastyear"))-date('W',strtotime("1 September $lastyear"))+1;
Similarly, whether the +1 needs to be determined by the Saturday/day judgment on September 1, so that line sixth can be replaced
return (date('W', $timestamp)%53)+$lastyearweeks;
Similarly, to determine the start date of the second semester, similar ideas to modify the last Retrun in 7, you can judge the date is the second semester of the first few weeks
You are all puzzled by the surface demand, if the current date is the first month of the start date, the landlord and the first floor of the logic although not entirely correct, but for the first few weeks is not necessary, because the crux of the problem is that 7 days is a week. My pseudo code is as follows
$startDate = 开学日期; //如2016-02-16$startDay = 开学这天是星期几; //如3表示周3$limitDay = 今天是自1970年以来第几天 - 开学日期是自1970年以来的第几天; //比如55天周日当每周的第一天了,此题中考虑这个问题没什么意义)$weekNumber = ceil(($limitDay + $startDay) / 7); //因为开学第一周可能不是整周,所以补上失去的天数
$weekNumber, that's what you want.
Thank you for your contribution. I think we can make an analysis from the following table (#注):
year |
(Spring) class date |
number of weeks of teaching (spring) |
Summer Begins |
(Autumn) class date |
(Autumn) number of teaching weeks |
Winter Break begins | New
Year's Eve: Weeks |
|
3/1 |
+ |
7/25 |
8/30 |
|
1/15 |
2/2:3 |
|
2/21 |
1/2 |
6/25 |
8/29 |
|
1/15 |
2:7 |
+ |
2/13 |
1/2 |
6/17 |
9/3 |
|
6 |
2/9:6 |
|
2/25 |
|
6/29 |
9/2 |
20 |
1/18 |
1/30:4 |
all |
2/17 |
/ |
6/21 |
9 /1 |
|
1/31 |
2/18:3 |
3 |
/2 |
/ |
7/ 4 |
8/31 |
|
1/23 |
2/8:1 |
|
2/22 |
1 8 |
6/25 |
8/29 |
Through analysis found, perhaps we can first analyze when the new year, and then the summer holiday from the new year before and after the two weeks, here also need some refinement, for example, and the Chinese New Year is the day of the week.
The fall semester starts from the 9/1 nearest Monday decision?
Spring starts from the start date (decided by the Chinese New Year)?
(#注: The statistical results may not be very correct, you can review.)
Does this need to be done with algorithms, or can the algorithm make it? Just record the time of the school calendar in the database.
School calendar out of a tube a year, that is 1 years can be recorded once, plainly, there is no law, this is the dean of the Office
I really think that the national colleges and universities are September 1, the Lunar New Year all let the Lantern Festival ah I in a certain 985 colleges and universities have never been at home after the Lantern festival