陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Quintiq file version 2.0
#parent: #root
StaticMethod GetStartOfPreviousPeriod (
  Date date,
  String timeunit,
  Number nroftimeunit
) declarative remote as DateTime
{
  Description: 'Return the start of the previous period given the date, time unit and nr of time unit'
  TextBody:
  [*
    // DWE2 Apr-25-2016 (modified)
    value := date.DateTime();
    
    // Hour
    if( timeunit = Translations::MP_GlobalParameters_Hour() )
    {
     value := date - Duration::Hours( nroftimeunit );
    }
    // Day
    else if( timeunit = Translations::MP_GlobalParameters_Day() )
    {
      value := date - Duration::Days( nroftimeunit );
    }
    // Week
    else if( timeunit = Translations::MP_GlobalParameters_Week() )
    {
      value := value - Duration::Weeks( nroftimeunit );
    }
    // Month
    else if( timeunit = Translations::MP_GlobalParameters_Month() )
    {
      value := PeriodSpecification_MP::GetStartOfPreviousMonth( value, nroftimeunit );
    }
    // Quarter
    else if( timeunit = Translations::MP_GlobalParameters_Quarter() )
    {
      value := PeriodSpecification_MP::GetStartOfPreviousMonth( value, nroftimeunit * 3 ); // A quarter = 3 month
    }
    // Year
    else if( timeunit = Translations::MP_GlobalParameters_Year() )
    {
      value := PeriodSpecification_MP::GetStartOfPreviousMonth( value, nroftimeunit * 12 ); // One year = 12 months
    }
    
    return value;
  *]
}