Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize-schedule #2

Open
michi-oshima opened this issue Apr 1, 2014 · 1 comment
Open

normalize-schedule #2

michi-oshima opened this issue Apr 1, 2014 · 1 comment
Assignees
Labels

Comments

@michi-oshima
Copy link

Hi Tim,

https://github.com/snh-clj/problem-solver/blob/master/rollover-time/src/snh_problems/rollover_time/tjm.clj#L4

For your normalize-schedule function to work properly, :hour must be explicitly specified in the schedule.

A general-purpose normalize-schedule might work like this:

  1. Given a schedule, take the "largest" time unit explicitly specified in the schedule. For example, :day is the largest time unit in {:day [1 15] :hour 6}.
  2. For any time unit that is "to the left of" the largest time unit in the schedule, we "fill in" all possible values. So, for :month we fill in [1..31]. For :year, we fill in, OK, some practical values like [2014..2114].
  3. For any time unit that is "to the right of" the largest time unit in the schedule, we "fill in" the default values. So for :minute, we fill in 0. For :second, also 0.

For example, the normalized version of the the schedule {:day [1 15], :hour 6} is:

  • {:year [2014..2114] :month: [1..12] :day [1 15] :hour 6 :minute 0 :second 0}

I did write a function to normalize the schedule in the way described above. But once again, it was pretty ugly.

@tmciver
Copy link
Contributor

tmciver commented Apr 1, 2014

Yeah, I had spent a long time thinking about this issue but in the end decided to go for a simpler solution even though I knew it wasn't 100% right.

I added a fix in commit d90b3fe. I think it's right but let me know if it's not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants