jeudi 2 juillet 2015

Storing day, week and month stats in rails

I've got a cron job which gathers stats for the previous day. Each morning it runs and updates day, week and month models.

day.rb 
belongs_to :week

week.rb
belongs_to :month
has_many :days

month.rb
has_many :weeks
belongs_to :foo

I'm planning on storing month and week as integers (so week commencing July 6th would be stored as 28). I was also thinking of doing the same with the day (so July 6th would be stored as 187). It means I'll also have to have a year field, so maybe this isn't the best approach?

Does anyone see any shortfalls in this system? I'll probably create a helper to do the conversions

How would you store the dates in a database like this? (I'm probably overthinking things and should just shut up and store dates, if so, feel free to let me know)

Aucun commentaire:

Enregistrer un commentaire