pjf / WebService-HabitRPG

Access the HabitRPG API from Perl
8 stars 5 forks source link

Task::active_today returns true when used on called on a task that repeats over an interval #35

Closed hoelzro closed 9 years ago

hoelzro commented 9 years ago

To reproduce:

Here's a dump of _raw from my example task:

_raw => {
    attribute => "str",
    challenge => {},
    checklist => [],
    collapseChecklist => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),
    completed => $VAR1->{_raw}{collapseChecklist},
    dateCreated => "2015-08-19T13:47:46.804Z",
    everyX => 28,
    frequency => "daily",
    history => [
      {
        date => "1440076254271",
        value => 0
      },
      {
        date => "1440212401025",
        value => 0
      },
      {
        date => "1440298800876",
        value => 0
      },
      {
        date => "1440340119563",
        value => 0
      }
    ],
    id => "xxxxxxxxxxxxxxxxxxxxxxxxxx",
    notes => "",
    priority => 1,
    repeat => {
      f => bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' ),
      m => $VAR1->{_raw}{repeat}{f},
      s => $VAR1->{_raw}{repeat}{f},
      su => $VAR1->{_raw}{repeat}{f},
      t => $VAR1->{_raw}{repeat}{f},
      th => $VAR1->{_raw}{repeat}{f},
      w => $VAR1->{_raw}{repeat}{f}
    },
    startDate => "2015-08-30T13:47:46.000Z",
    streak => 0,
    tags => {},
    text => "Monthly Review",
    type => "daily",
    value => 0
  }

Thanks for all your hard work on this module!

hoelzro commented 9 years ago

I dug into this a bit, and here's the logic that HabitRPG itself uses for this:

https://github.com/HabitRPG/habitrpg/blob/ab91a6fba96ba1585a11ac252d80c1868c9d009d/common/script/index.coffee#L96

It's not terribly complex, but to do things right, we'll probably need to use a date module like DateTime or one of its friends.

hoelzro commented 9 years ago

@pjf Do you have any thoughts on how you'd like this to be implemented? I'm happy to do it myself, I just want to make sure it matches up with your vision for the project.

hoelzro commented 9 years ago

Considering that this module uses the Artistic license and HabitRPG is GPLv3, it would probably be best not to look at the HabitRPG code. Unfortunately, now I'm "infected", so I think someone other than me needs to write this in a blackbox environment. Is it ok if I describe the algorithm, and someone writes Perl code based on that? Or maybe I'm being too careful?

pjf commented 9 years ago

The most straightforward implementation I can see would be to add it to the HabitRPG API, provided @lefnire or the other appropriate habit people don't have any objections. :)

Otherwise I'd say that clean-rooming an implementation is definitely being too careful. :)

hoelzro commented 9 years ago

This is fixed now!