In 1C:Enterprise dates include time with an accuracy up to one second. If you do not specify time explicitly, it is set to 00:00:00. A date difference is expressed in seconds. For example, if you specify a period between 01/01/2012 and 01/31/2012, it means a period from the first second of 01/01/2012 till the first second of 01/31/2012. Therefore, it does not include January 31, except the first second of this day. If you want to specify a full month period, set the boundaries from 01/01/2012 00:00:00 to 01/31/2012 23:59:59. Note that boundaries from 01/01/2012 to 02/01/2012 do not describe a full month period because the first second of February 1, 2012 is included.
Normally, users enter period boundaries as dates without time. When a user enters a period between 01/01/2012 and 01/31/2012, they mean the entire month. If you pass these values to system functions or queries, they will be interpreted as a period from 01/01/2012 00:00:00 to 01/31/2012 00:00:00. Therefore, you have to convert the end of period to the end of day. You can use the EndOfDay() function for this purpose. It returns the date with time set to the last second of the specified day. For example, Date(2012, 1, 31, 23, 59 ,59) and EndOfDay(Date(2011, 1, 31) give the same result.
Turnovers = AccumulationRegisters.CompanyFunds.Turnovers(Date(2012, 1, 1), EndOfDay(Date(2012, 1, 31)));
1C:Enterprise allows specifying date and time together with a related document. The PointInTime object stores both a date and a related document; it consists of a date and a reference to the recorder. The date of the point in time might not match the document date because documents can write register records for any period, not just for periods matching the document dates. To get the point in time that includes the document date and the document itself, use the PointInTime method of the document. For example, if you want to calculate document balance, passing a reference to the document to a method that calculates balances is incorrect. You have to pass the PointInTime object; you can get it by using the PointInTime() method of the document reference or create it using the New operator.
Balance = AccumulationRegisters.CompanyFunds.Balance(DocumentRef.PointInTime());
Balances = AccumulationRegisters.CompanyFunds.Balances(New PointInTime(Document.Date, Document));
System functions and virtual tables use parameters of Date and PointInTime types for calculating balance and turnovers. Balance is calculated for a specific point in time. When a point in time is specified for balance calculation purposes, the point itself is excluded from calculations by default. If a point in time's date is 11/21/2012 12:00:00, balance is calculated until (but not including) this point in time.
For example, an accumulation register contains the following records:
|11/21/2012 11:59:59||Receipt #1||Income||Refrigerator||5|
|11/21/2012 12:00:00||Expense #1||Expense||Refrigerator||2|
|11/21/2012 12:00:00||Expense #2||Expense||Refrigerator||1|
The balance as of 11/21/2012 12:00:00 is 5 refrigerators. The balance as of 11/21/2012 12:00:01 is 2 refrigerators. To calculate the balance including the specified point in time, use the Boundary object. It allows you to specify whether you want to include the point in time in the calculation. In the previous example, the balance for the boundary that is set as date 11/21/2012 12:00:00 (inclusive) is 2 refrigerators. Both expense documents Expense #1 and Expense #2 are included in the calculation because the boundary is set using a value of Date type. If you set the boundary as a point in time that contains date 11/21/2012 12:00:00 and recorder Expense #1, Expense #2 is excluded from the calculation and the resulting balance is 3 refrigerators. The following figure shows boundary positions on the time axis:
Unlike balances, turnovers are calculated for periods that have two boundaries. By default, both boundaries have "inclusive" type. But the meaning of "inclusive" and "excusive" differs for beginning and ending boundaries. For ending boundaries, the meaning is the same as in balance calculation: if a boundary is specified using a date, "inclusive" means "the end of second", and "exclusive" means "the beginning of second". For beginning boundaries, the contrary is true: "inclusive" means "the beginning of second", and "exclusive" means "the end of second". The following figure shows inclusive and exclusive boundaries for the period from 11/21/2012 00:00:00 to 11/21/2012 23:59:59.