Dear all,
following something I’ve posted in the old forum, I’m working on something to handle the collection of documents which can have partial dates:
- I’m collecting PLANS (prototype plano_p in attached file);
- Each PLAN can have multiple DOCUMENTS (prototype documento_p in attached file);;
- Each DOCUMENT can have multiple DATES (prototype data_doc_p in attached file);
- Each DATE can be defined in one of three ways:
a- year (eg. 1980);
b- year and month (eg. 1980-02);
c- year, month and day (eg. 1980-02-10).
Meaning, inside a PLAN I have multiple DOCS, each with multiple DATES (as children notes: their $Text is passed onto a $KeyAttribute, which is then queried for the number of values to determine the INITIAL DATE and FINAL DATE based on the original DATE).
This means:
-
if the DATE is defined as 1980,
INITIAL DATE will become 01/01/1980 00:00 and
FINAL DATE will become 31/12/1980 23:59
(i.e. whole year); -
if the DATE is defined as 1980-03,
INITIAL DATE will become 01/03/1980 00:00 and
FINAL DATE will become 31/03/1980 23:59
(i.e whole month); -
if the DATE is defined as 1980-03-20,
INITIAL DATE will become 20/03/1980 00:00 and
FINAL DATE will become 20/03/1980 23:59
(i.e whole day);
These calculations are made on the notes with the DATE prototype; then the DOC will collect all the initial and final dates and assign the minimum initial date and maximum final date to itself; and then the PLAN will do the same for all DOCS, meaning:
-
the initial date of the PLAN is the newest initial date of all DOCS that make part of it;
-
the final date of the PLAN is the oldest final date of all DOCS that make part of it;
-
the initial date of the DOC is the newest initial date of all DATES that make part of it;
-
the final date of the DOC is the oldest final date of all DATES that make part of it;
It seems to be working quite ok, except when defining older dates with YYYY-MM only. In the TBX attached to this post you will find a note, highlighted in red, where the problem occurs:
The note “1920-03” gets correctly assigned the INITIAL DATE of 01/03/1920 00:00, but the wrong FINAL DATE of 07/05/2056, 23:59;
However, the note “1970-03” gets correctly assigned both INITIAL and FINAL DATES, i.e. 01/03/1970, 00:00 and 31/03/1970, 23:59.
“1920” and “1920-03-20” also get evaluated ok. The problem is only when the date is defined only by year and month, and I suspect it must have something to do with what I’ve setup to calculate the last day of the month:
if ($data_doc_p_parcial.count == 2) {
$data_doc_p_final_norm = date("01/" + $data_doc_p_parcial.at(1) + "/" + $data_doc_p_parcial.at(0));
$data_doc_p_final_norm = date((($data_doc_p_final_norm +1month)-1day));
};
(when encountering a date defined by 2 parameters (i.e. YYYY and MM) it makes the FINAL DATE first become the first day of that month, then adds 1 month and subtracts 1 day).
PHEW. Hope it made sense and you can help me find the bug or the problem on my code or a cleaner way to do all this.
Here is the TBX file:
broadDefinitionOfDates.tbx (86.8 KB)
PS: I’m loading edicts into the prototypes through their rules which fetch a specific note’s $Text (feels more comfortable to edit the code in this way…)
Thanks! I’d like to post this in the examples when ready. May be of some use