Date diff calculator

After 1 hour of usage, I managed to make date diff calculator

I need this kind of functionality few time per month, so I am going to use it.
Maybe it is useful for somebody else also.

I am a professional software developer and have been using python for last 8+ years.
This is part of the secret :slight_smile:.

On this theme, here are some interesting convenience date thinggies that make links set date picker controls to some predetermined types. The date pickers are :

date_picker_start
date_picker_end

The clue is in the function name. It should be quite obvious. I have links called “link_today” (etc) and their click events call the following functions. Most are obvious but the ones that might not be are :

endstart : this sets the end date to the same as the start date (saves you having to select the end date as well as the start date when they are the same).

eom : you choose a start date and this link will set the end date to the last day of the month in the start date.

Hope these are useful to someone.

from datetime import datetime, timedelta, date
...

  def link_today_click (self, **event_args):
    # This method is called when the link is clicked
    self.date_picker_start.date=datetime.now().date()
    self.date_picker_end.date=datetime.now().date()
    self.set_link_colour(self.link_today)

  def link_yesterday_click (self, **event_args):
    # This method is called when the link is clicked
    self.date_picker_start.date=datetime.now().date() - timedelta(days=1)
    self.date_picker_end.date=datetime.now().date() - timedelta(days=1)
    self.set_link_colour(self.link_yesterday)

  def link_thismonth_click (self, **event_args):
    # This method is called when the link is clicked
    self.date_picker_start.date=date(date.today().year, date.today().month, 1)
    self.date_picker_end.date=datetime.now().date()
    self.set_link_colour(self.link_thismonth)
    
  def link_lastmonth_click (self, **event_args):
    # This method is called when the link is clicked
    prev = date.today().replace(day=1) - timedelta(days=1)
    self.date_picker_start.date=date(prev.year, prev.month, 1)
    self.date_picker_end.date=date(prev.year, prev.month, prev.day)
    self.set_link_colour(self.link_lastmonth)

  def link_endstart_click (self, **event_args):
    # This method is called when the link is clicked
    self.date_picker_end.date=self.date_picker_start.date
    self.set_link_colour(self.link_endstart)

  def link_eom_click (self, **event_args):
    # This method is called when the link is clicked
    fom = self.date_picker_start.date.replace(day=1)
    eom = (fom + timedelta(days=33)).replace(day=1) - timedelta(days=1)
    self.date_picker_start.date=fom
    self.date_picker_end.date=eom
    self.set_link_colour(self.link_eom)