#Java Spring Framework Date, Date Time

24 messages · Page 1 of 1 (latest)

robust stream
#

Hello guys so i have entity called Team, and i have private LocalDate starttime, and private LocalDate endtime, also i have private boolean finished. so i want to write method (with validations) that whenever team opens it should has its lifetime 6 month and then it should become finished . how ?

open anvilBOT
#

This post has been reserved for your question.

Hey @robust stream! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

tacit lake
#

you mean when endtime is more than 6 months after starttime?

robust stream
#

for example team started today 1/14/2023 (using local date time)

#

and it should end 6 months from now

#

and team should become automatically finished

tacit lake
#

so the finished should only depend on whether endtime is before or after tze current date?

robust stream
#

after the current date

#

nope nope

tacit lake
#

ok

robust stream
#

on endtime

tacit lake
#

yeah, endtime should be compared to the current date, right?

robust stream
#

right

#

and i want to validate that

tacit lake
#

Are you using a getter for finished?

robust stream
#

yes for both

tacit lake
#

What about that: You remove finished but instead of removing the getter, you change it to:

public boolean isFinished(){
    return LocalDate.now().isAfter(getEndtime());
}
#

then you don't store whether it is finished but calculate it on the fly

robust stream
#

ooh i like the logic

tacit lake
#

and if the end time is always 6 months after the start time, you could also do something similar for endtime if you want to

robust stream
#

ok ty i will try

#

really helped

tacit lake
#

no problem