I'm parsing Wikidata JSON datasets to collect historic data. So far I haven't found the right format to store them in PHP / MySQL (via Doctrine).
For the last few millennia, DateTime seems to work, but I don't want to limit my application to that. It might be totally possible that it will have to process the start time
property of the Universe. Besides, I also want to store the precision of the data, since we might know the rough year of birth of one person and the exact minute for another one.
(Edit: For now, dates are enough, I can live without the time, my example was exaggerated. Still, I sometimes know the exact date, sometimes just the month or even the year.)
I've thought about creating my own class for dates (I'm not planning to calculate time differences or something like that), but I also don't want to re-invent the wheel.
Search results on a certain search engine as well as here are ... underwhelming, sadly.
Any ideas or experience that you can share?
For a kind of similar use-case, we ended up with storing values for each period of time, allowing to store everything in the db and query at various precision levels.
class YourAwesomeDateManager {
public
$millenium,
$century,
$decade,
$year,
$month;
// and so on...
function setDate() {
// Hydrate with the best precision available
}
public function getDate ($precision) {
// ...
}
}
This allows you to retrieve different date formats, and return 0
for unavailable precision fields
The thing is that there is no common name usage for periods above milleniums. So you'll have to be creative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With