Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Consistent broad definition of dates (Read 1486 times)
B.Moreira
Full Member
*
Offline



Posts: 71

Consistent broad definition of dates
Jun 1st, 2016, 12:50pm
 
Hi everyone. I hope the title makes sense: I am trying to achieve a consistent definition of dates when there is some information missing (eg. the precise day or month of a given event).

Consider Tinderbox default behavior when you introduce something into $StartDate or $EndDate:

if you put "2020", the output will be "15/06/20, 00:00"
if you put "10/2020", the output will be "01/10/20, 00:00"
if you put "05/10/2020", the output will be 05/10/20, 17:21"

I am trying to make this more consistent (IMHO) by using two user-defined list-type key attributes ($PartialStartDate and $PartialEndDate) which get interpreted by a set of rules and produce my desired $StartDate and #EndDate as follows:

if I put year only in $PartialStartDate, $StartDate gets assigned the first day of that year, at 00:00;
if I put year only in $PartialEndtDate, $EndtDate gets assigned the last day of that year, at 23:59;

if I put month and year only in $PartialStartDate, $StartDate gets assigned the first day of that month, at 00:00;
if I put month and year only in $PartialEndtDate, $EndtDate gets assigned the last day of that month, at 23:59;

if I put month, year and day in $PartialStartDate, $StartDate gets assigned that day/month/year, at 00:00;
if I put month, year and day in $PartialEndtDate, $EndDate gets assigned that day/month/year, at 23:59;

(being list-type attributes, year, month and day are separated by ";" and not by "/")

Other rules state that:

if the $PartialStartDate is empty, the $PartialEndDate is cleared as well (no end dates without start dates);

- $PartialEndDate gets assigned the content of $PartialStartDate, if empty; this allows, for example:

you place 05/2020 in $PartialStartDate;
05/2020 gets automatically assigned to $PartialEndDate;
$StartDate gets assigned "01/05/2020, 00:00" and $EndDate gets assigned "31/05/2020, 23:59";
if needed, $PartialEndDate can be changed to other date, and $EndDate will be updated.


The rules are as follows:

Code:
f ($PartialStartDate.count=3)
{
$StartDate = date($PartialStartDate.at(2) / $PartialStartDate.at(1) / $PartialStartDate.at(0) + ",00:00:00");
};

if ($PartialStartDate.count=2)
{
$StartDate = date($PartialStartDate.at(1) / $PartialStartDate.at(0) / 01 + ",00:00:00");
};

if ($PartialStartDate.count=1)
{
$StartDate = date($PartialStartDate.at(0) / 01 / 01 + ",00:00:00");
};

if ($PartialEndDate.count=3)
{
$EndDate = date($PartialEndDate.at(2) / $PartialEndDate.at(1) / $PartialEndDate.at(0) + ",23:59:59");
};

if ($PartialEndDate.count=2)
{
$EndDate = date($PartialEndDate.at(1) / $PartialEndDate.at(0) / 01 + ",23:59:59") + 1month - 1day;
};

if ($PartialEndDate.count=1)
{
$EndDate = date($PartialEndDate.at(0) / 12 / 31 + ",23:59:59");
};

if ($PartialEndDate="") {
$PartialEndDate=$PartialStartDate;
};

if ($PartialStartDate="") {
$PartialEndDate=;
$StartDate=;
};

if ($PartialEndDate="") {
$EndDate=;
};
 

i


I'm sharing with you the TBX file https://www.dropbox.com/s/z7x0l2a0hcv3vak/broad_date_definition.tbx?dl=0

so all critics are welcome! Namely:

if Tinderbox has a native way of doing this and I didn't knew;
if there's a more elegant way to write the set of rules;

and a PROBLEM that I am having trouble sorting out: if I place "1949" in year, it gets interpreted as "2049"; but "1950" gets interpreted as "1950". I'd like years to be interpreted literally, with 4-digits ... trying but having no luck so far. So help appreciated to solve this one! Cheesy

Thanks.
Bruno.
Back to top
 
« Last Edit: Jun 01st, 2016, 5:47pm by Mark Bernstein »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Consistent broad definition of dates
Reply #1 - Jun 1st, 2016, 1:43pm
 
OK, so we enter '10;2020' rather than '10/2020'.

I opened your TBX and added '1949' to $PartialStartDate of 'Event 1' and got a $startDate of 1/1//1949 00:00.  FWIW, I'm on a UK settings OS X. Perhasp the 1949->2049 issue is linked to your locale?
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
B.Moreira
Full Member
*
Offline



Posts: 71

Re: Consistent broad definition of dates
Reply #2 - Jun 1st, 2016, 3:14pm
 
Hmm yes, something with locale settings in OSX Preferences ... giving trouble.

If I define short date format to dd/MM/yy and put "1949" in $PartialStartDate and $PartialEndDate, I get:

$StartDate = 01/01/2049, 00:00
$EndDate = 31/12/2049, 23:59

If I define short date format to dd/MM/yyyy and put "1949" in $PartialStartDate and $PartialEndDate, I get:

$StartDate = 01/01/1949, 00:00
$EndDate = 31/12/1949, 23:59

but if you place "10;1949" in $PartialStartDate, then $EndDate gets a very weird value ...

Huh
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Consistent broad definition of dates
Reply #3 - Jun 1st, 2016, 5:44pm
 
I'd report this to support for more detailed triage.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
B.Moreira
Full Member
*
Offline



Posts: 71

Re: Consistent broad definition of dates
Reply #4 - Jun 2nd, 2016, 5:43am
 
I think I got it. Here's a new TBX: https://www.dropbox.com/s/ruckv6pnx298ps0/broad_date_definition%202.tbx?dl=0

I have replaced the $Rule to this:

Code:
if ($PartialStartDate.count=1) {
$StartDate = "01/01/" + $PartialStartDate.at(0);
$StartDate=hour($StartDate,0);
$StartDate=minute($StartDate,0);
$StartDate=second($StartDate,0);
};

if ($PartialEndDate.count=1) {
$EndDate = "31/12/" + $PartialEndDate.at(0);
$EndDate =hour($EndDate,23);
$EndDate =minute($EndDate,59);
$EndDate =second($EndDate,59);
};

if ($PartialStartDate.count=2) {
$StartDate = "01/" + $PartialStartDate.at(0) + "/" + $PartialStartDate.at(1);
$StartDate=hour($StartDate,0);
$StartDate=minute($StartDate,0);
$StartDate=second($StartDate,0);
};

if ($PartialEndDate.count=2) {
$EndDate = "31/" + $PartialEndDate.at(0) + "/" + $PartialEndDate.at(1);
$EndDate =hour($EndDate,23);
$EndDate =minute($EndDate,59);
$EndDate =second($EndDate,59);
};

if ($PartialStartDate.count=3) {
$StartDate = $PartialStartDate.at(0) + "/" + $PartialStartDate.at(1) + "/" + $PartialStartDate.at(2);
$StartDate=hour($StartDate,0);
$StartDate=minute($StartDate,0);
$StartDate=second($StartDate,0);
};

if ($PartialEndDate.count=3) {
$EndDate = $PartialEndDate.at(0) + "/" + $PartialEndDate.at(1) + "/" + $PartialEndDate.at(2);
$EndDate=hour($EndDate,23);
$EndDate=minute($EndDate,59);
$EndDate=second($EndDate,59);
};

if ($PartialEndDate="") {
$PartialEndDate=$PartialStartDate;
};

if ($PartialStartDate="") {
$PartialEndDate=;
$StartDate=;
};

if ($PartialEndDate="") {
$EndDate=;
};

$Interval=interval($StartDate,$EndDate); 



Not very pretty but seems to work. Also this implies that you have set 4 digit year in system prefs in OSX (at short date format) or dates will get messed up whenever there's a calculation.

There may be a cleaner way to do it but for now, seems be enough for me!
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Consistent broad definition of dates
Reply #5 - Jun 2nd, 2016, 12:11pm
 
Side note: I see the conditional query code in your if(condition) statements uses legacy code to test 'is equal to'. As this syntax may stop working at some point, I'd suggest using the more recent form, i.e. '== 'test equality instead of '=' assignment.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
B.Moreira
Full Member
*
Offline



Posts: 71

Re: Consistent broad definition of dates
Reply #6 - Jun 2nd, 2016, 12:29pm
 
Thanks for the notice Mark. Must not forget that.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Consistent broad definition of dates
Reply #7 - Jun 2nd, 2016, 12:30pm
 
Code:
if ($PartialStartDate.count=1) {
$StartDate = "01/01/" + $PartialStartDate.at(0);
$StartDate=hour($StartDate,0);
$StartDate=minute($StartDate,0);
$StartDate=second($StartDate,0);
}; 


I'd write this as:

if ($PartialStartDate.count==1) {
$StartDate = date("01/01/" + $PartialStartDate.at(0));
$StartDate=hour($StartDate,0));
$StartDate=minute($StartDate,0);
$StartDate=second($StartDate,0);
};


Changes in blue. Rather than say $MyDate="today", it is now suggested to use $MyDate=date("today")

Whilst it makes no real difference in this context, note you can use the following syntax forms interchangeably:

$StartDate = hour($StartDate,0)
$StartDate.hour = 0

Arguably, the second is a little simpler/shorter.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
B.Moreira
Full Member
*
Offline



Posts: 71

Re: Consistent broad definition of dates
Reply #8 - Jun 2nd, 2016, 12:37pm
 
Thanks again. At a given time I removed the date() because I was getting odd results, but the problem was with System Preferences / Short Date format, which was displaying years with 2 digits instead of 4. As a result, date() did a recalculation and the result was "wrong". But now I guess it's ok to get back at it  Smiley
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print