F
F
Falseclock2018-08-20 12:52:44
Database design
Falseclock, 2018-08-20 12:52:44

What is the best way to approach storing periodicities?

There is some entity. Let's say it's fruits / vegetables / greens.
We have for example:

  • apples
  • strawberry
  • tomatoes
  • parsley

We need to describe the frequency of harvesting in a period. One entity can have 1 crop per period and another 3 crops.
Plus, we need to describe at what time the crop ripens, for example, only on even numbers or every first Monday of the month.
In .. train schedule depending on the season. While writing - I found a better example)) With trains - that's it.
This is how it would be more correct to describe the structure of data storage by periodicity, time and seasonality, given that it can be daily, only on weekdays, or even, in general, for everyone. I want the flexibility of the structure, but something is hanging and I can’t think of it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2018-08-20
@Falseclock

Get inspired by crontab :)
It has some peculiarities, but you can come up with your own rules:

  • All conditions (start time) are checked by "logical AND", except for the conditions "day of the week" and "day of the month" - specified together, they are processed by "logical OR", that is, "on any of the days", which is reflected in the documentation ( Ubuntu, Debian, FreeBSD). However, this logic is not obvious and does not allow you to create a condition like "the first Monday of every month" or "every Friday on the 13th". Developers do not change this behavior, considering it as a standard.
  • The crontab syntax used to run every few minutes with an offset can lead to unexpected results. Thus, entry 1-56/5 * * * * will not trigger on the 01st minute of every hour; to trigger "every 5 minutes starting from the 1st minute of the hour" use the format 1-59/5 * * * * or 1,6,11,16,21,26,31,36,41,46,51,56 * * * *.

R
Roman Mirilaczvili, 2018-08-20
@2ord

You can define a set of individual periodicities, each of which:
Each periodicity can be performed independently of the other, in parallel in the same time interval and sequentially, or even with an intersection with other time intervals.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question