I have different types of dates formatting like:
27 - 28 August 663 CE
22 August 1945 19 May
May 4 1945 – August 22 1945
I will be updating this answer more and more while I will build new parsers. Feel free to contribute.
So for these formats, I'll do:
27 - 28 August 663 CE
22 August 1945 19 May
May 4 1945 – August 22 1945
5-10 February 1720
JS
months = new Set(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);
for(var i = 0; i < dateText.length; i++) {
d += dateText[i] + ' ';
}
var words = d.replace("–", " ").replace("-", " ").replace(",", " ").replace("/", " ").split(' ');
words = $.grep(words, function(n, i){
return (n !== "" && n != null);
});
var array = words;
var newArray = array.filter(function(v){return v!==''});
for (const word of newArray) {
if (months.has(word)) {
spacetime[0].Time.months.push(word);
} else if (+word < 32) {
spacetime[0].Time.days.push(+word);
} else if (+word < 2200) {
spacetime[0].Time.years.push(+word);
} else if (/\w+/.test(word)) {
spacetime[0].Time.suffixes.push(word);
}
jSon example:
"Time": {
"days": [
22
],
"months": [
"August"
],
"years": [
1945
],
"suffixes": [
"10:25",
"(UTC+1)"
]