Changeset 7458 for trunk/MagicSoft/Mars/mbase/MTime.cc
- Timestamp:
- 12/21/05 20:34:05 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MTime.cc
r7450 r7458 480 480 // -------------------------------------------------------------------------- 481 481 // 482 // Return Mjd of the first day (a monday) which belongs to week 1 of 483 // the year give as argument. The returned Mjd might be a date in the 484 // year before. 485 // 486 // see also MTime::Week() 487 // 488 Int_t MTime::GetMjdWeek1(Short_t year) 489 { 490 MTime t; 491 t.Set(year, 1, 4); 492 493 return (Int_t)t.GetMjd() + t.WeekDay() - 6; 494 } 495 496 // -------------------------------------------------------------------------- 497 // 482 498 // Get the week of the year. Valid week values are between 1 and 53. 483 // 54 is returned if the day belongs to Week=1 of the next year, 484 // 0 if it belongs to the Week=53 and -1 if it belongs to the Week=52 485 // of the last year (In this case there is no week 53!) 486 // 487 Int_t MTime::Week() const 488 { 489 static const Int_t kFrSaSo = BIT(kFriday) | BIT(kSaturday) | BIT(kSunday); 490 static const Int_t kTuWeTh = BIT(kTuesday) | BIT(kWednesday) | BIT(kThursday); 491 492 MTime t; 493 t.Set(Year(), 1, 1); 494 495 // The weekday of Jan 1st. 496 const Int_t day1st = 1<<t.WeekDay(); 497 498 // The number of weeks since the first Monday in the year 499 Int_t week = (DayOfYear()-1 + (t.WeekDay()+6)%7) / 7 + 1; 500 501 // Correct the week number if the year has started with Fr, Sa or So 502 if (day1st & kFrSaSo) 503 week--; 504 505 // If the week number is 53 it might already belong to the next year 506 if (week == 53) 499 // If for a january date a week number above 50 is returned the 500 // week belongs to the previous year. If for a december data 1 is 501 // returned the week already belongs to the next year. 502 // 503 // The year to which the week belongs is returned in year. 504 // 505 // Die Kalenderwochen werden für Jahre ab 1976 berechnet, da mit 506 // Geltung vom 1. Januar 1976 der Wochenbeginn auf Montag festgelegt 507 // wurde. Die erste Woche ist definiert als die Woche, in der 508 // mindestens 4 der ersten 7 Januartage fallen (also die Woche, in der 509 // der 4. Januar liegt). Beides wurde damals festgelegt in der DIN 1355 510 // (1974). Inhaltlich gleich regelt das die Internationale Norm 511 // ISO 8601 (1988), die von der Europäischen Union als EN 28601 (1992) 512 // übernommen und in Deutschland als DIN EN 28601 (1993) umgesetzt 513 // wurde. 514 // 515 Int_t MTime::Week(Short_t &year) const 516 { 517 // Possibilities for Week 1: 518 // 519 // Mo 4.Jan: Mo 4. - So 10. -0 6-6 520 // Di 4.Jan: Mo 3. - So 9. -1 6-5 521 // Mi 4.Jan: Mo 2. - So 8. -2 6-4 522 // Do 4.Jan: Mo 1. - So 7. -3 6-3 523 // Fr 4.Jan: Mo 31. - So 6. -4 6-2 524 // Sa 4.Jan: Mo 30. - So 5. -5 6-1 525 // So 4.Jan: Mo 29. - So 4. -6 6-0 526 // 527 const Int_t mjd2 = GetMjdWeek1(Year()-1); 528 const Int_t mjd0 = GetMjdWeek1(Year()); 529 const Int_t mjd3 = GetMjdWeek1(Year()+1); 530 531 // Today 532 const Int_t mjd = (Int_t)GetMjd(); 533 534 // Week belongs to last year, return week of last year 535 if (mjd<mjd0) 507 536 { 508 t.Set(Year()+1, 1, 1); 509 510 const Int_t daynext = 1<<t.WeekDay(); 511 return daynext&kTuWeTh ? 54 : 53; 537 year = Year()-1; 538 return (mjd-mjd2)/7 + 1; 512 539 } 513 540 514 // If the week number is 53 it might still belong to the last year515 if ( week == 0)541 // Check if Week belongs to next year (can only be week 1) 542 if ((mjd3-mjd)/7==1) 516 543 { 517 t.Set(Year()-1, 1, 1); 518 519 const Int_t dayprev = 1<<t.WeekDay(); 520 return !(dayprev&kFrSaSo) && (day1st&kFrSaSo) ? 0 : -1; 544 year = Year()+1; 545 return 1; 521 546 } 522 547 523 return week; 548 // Return calculated Week 549 year = Year(); 550 return (mjd-mjd0)/7 + 1; 524 551 } 525 552
Note:
See TracChangeset
for help on using the changeset viewer.