2017년 3월 26일 일요일

Convert days into years , months and days.


Is there any way to convert the difference between two dates into years, months and days?

--
This is tricky.

It can't be simply done by counting days, because the number of days in a month varies by month and by year.

Maybe the problem can be broken down into simpler problems by establishing
landmarks at the beginning and end of years and months, and using those to 
get years and then months and then days.

But this would involve a pretty bushy if/then/else tree comparing the order of date parts
versus each other.

--
Yes. It can be done using couple of blocks. See my post here: https://amerkashi.wordpress.com/2017/03/11/dateutils-extension/

--
Thank you, Mr.Abraham Getzler.

Thank you,  Mr. Hossein A
--
It can be done in blocks using decreasing overshoots and the help of clock blocks.

See attached.

This might still be controversial, depending on your test date ranges.








-- 
Thank you, Mr.Abraham Getzler.
It took some time to completely comprehend the blocks. A youtube video of the process of creating various procedures would have been a spellbound effect on the audience. That would be asking too much of your time. 
The solution is amazing.

--
I regret that my speaking voice is too soft and my accent too strong for decent You Tube video production.
I prefer to document in text form, which is also more amenable to Google Translate.

The problem you posed has to be regarded as a trick question,
a logical impossibility usually used to incapacitate murderous robots,
(I like you better because you are identical to your twin - Star Trek), fluster 
courtroom defendants ("When did you stop beating your wife?"), 
or annoy mathematicians ("What's the highest positive integer?").

For example, what is one month after January 31?
Is it February 31?
Or is it the last day of February, either the 28th or 29th?
Or is it some constant number of days after January 31, say 30 days?

I dodged that tough question in my blocks by using the AI2 .AddMonth block
to do the dirty work, to absolve myself of blame when things go wrong.

This is a good student example, because it can stimulate debate
and sharpen thinking.

--
I forgot to include this reference in my prior post regarding the definition of a month ...

So the proper answer to your post also depends on the application
and the legal jurisdiction.

--
Mr.Abraham Getzler,
The App is just running fine, even if I disable the two blocks Viz. DatePicker.AfterDateSet. What is the purpose of these blocks?


--
The App is just running fine, even if I disable the two blocks Viz. DatePicker.AfterDateSet. What is the purpose of these blocks?
I assumed it was necessary to explicitly set the text in the Date Picker to match the date that was chosen.

I have not tested that assumption.

Maybe I was wrong?

--
Mr.Abraham Getzler,
I am an amateur. You are a professional. I am just curious to know the reason for those blocks.
Thank you.

--
I just ran a test on the emulator with those blocks disabled.

If you closely examine the emulator, you will see it saying
that there is 1 year between 3/24/2017 and 3/24/2017.

So the Date Picker does not update its .Text value automatically,
and my blocks were necessary.

The Date Picker .Text values are an important part of the GUI
for this app, in that they provide transparency and make it easier to
verify the correct operation of the app at a glance.

Having both the input and output values of a calculation
simultaneously available on the screen increase the
trustworthiness of an app.

Thanks for the interesting post!


-- 
I ran it on AI Companion with my phone. It is just working fine.
Thank you, for your interest.

--

댓글 없음:

댓글 쓰기