Compare commits
3 commits
53a8ec680a
...
a13262a273
Author | SHA1 | Date | |
---|---|---|---|
a13262a273 | |||
bd0f3adba3 | |||
26fc5a0693 |
4 changed files with 2888 additions and 2743 deletions
File diff suppressed because it is too large
Load diff
|
@ -133,12 +133,13 @@ impl From<ParsedDate> for OffsetDateTime {
|
|||
}
|
||||
}
|
||||
|
||||
fn filter_str(string: &str) -> String {
|
||||
/// Prepare the datestring for parsing: lowercase and filter out unnecessary punctuation
|
||||
fn filter_datestr(string: &str) -> String {
|
||||
string
|
||||
.to_lowercase()
|
||||
.chars()
|
||||
.filter_map(|c| {
|
||||
if c == '\u{200b}' || c.is_ascii_digit() {
|
||||
if matches!(c, '\u{200b}' | '.') || c.is_ascii_digit() {
|
||||
None
|
||||
} else if c == '-' {
|
||||
Some(' ')
|
||||
|
@ -197,7 +198,7 @@ fn parse_textual_month(entry: &dictionary::Entry, filtered_str: &str) -> Option<
|
|||
/// Returns [`None`] if the date could not be parsed.
|
||||
pub fn parse_timeago(lang: Language, textual_date: &str) -> Option<TimeAgo> {
|
||||
let entry = dictionary::entry(lang);
|
||||
let filtered_str = filter_str(textual_date);
|
||||
let filtered_str = filter_datestr(textual_date);
|
||||
|
||||
let qu: u8 = util::parse_numeric_prod(textual_date).unwrap_or(1);
|
||||
|
||||
|
@ -244,7 +245,7 @@ pub fn parse_timeago_dt_or_warn(
|
|||
pub fn parse_textual_date(lang: Language, textual_date: &str) -> Option<ParsedDate> {
|
||||
let entry = dictionary::entry(lang);
|
||||
let by_char = util::lang_by_char(lang);
|
||||
let filtered_str = filter_str(textual_date);
|
||||
let filtered_str = filter_datestr(textual_date);
|
||||
|
||||
let nums = util::parse_numeric_vec::<u16>(textual_date);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
60
testfiles/dict/format_dict.js
Normal file
60
testfiles/dict/format_dict.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
const fs = require("fs");
|
||||
const DICT_PATH = "dictionary.json";
|
||||
|
||||
const dict = JSON.parse(fs.readFileSync(DICT_PATH));
|
||||
|
||||
const TA_TOKENS = { s: 1, m: 2, h: 3, D: 4, W: 5, M: 6, Y: 7 };
|
||||
|
||||
// Sort a dictionary by value
|
||||
function sortDict(dict) {
|
||||
// Create items array
|
||||
const items = Object.keys(dict).map(function (key) {
|
||||
return [key, dict[key]];
|
||||
});
|
||||
// Sort the array based on the second element
|
||||
items.sort(function (first, second) {
|
||||
let d1;
|
||||
if (typeof first[1] === "string") {
|
||||
// Check for timeago token
|
||||
const tokenPat = /^(\d*)([smhDWMY])$/;
|
||||
const m1 = first[1].match(tokenPat);
|
||||
const m2 = second[1].match(tokenPat);
|
||||
if (m1 !== null && m2 !== null) {
|
||||
const tok1 = TA_TOKENS[m1[2]];
|
||||
const tok2 = TA_TOKENS[m2[2]];
|
||||
if (tok1 === tok2) {
|
||||
const n1 = parseInt(m1[1]) || 0;
|
||||
const n2 = parseInt(m2[1]) || 0;
|
||||
d1 = n1 - n2;
|
||||
} else {
|
||||
d1 = tok1 - tok2;
|
||||
}
|
||||
} else {
|
||||
d1 = first[1].localeCompare(second[1]);
|
||||
}
|
||||
} else {
|
||||
d1 = first[1] - second[1];
|
||||
}
|
||||
if (d1 === 0) {
|
||||
return first[0].localeCompare(second[0]);
|
||||
}
|
||||
return d1;
|
||||
});
|
||||
|
||||
const newDict = {};
|
||||
items.forEach((item) => {
|
||||
newDict[item[0]] = item[1];
|
||||
});
|
||||
return newDict;
|
||||
}
|
||||
|
||||
for (const [mainLang, entry] of Object.entries(dict)) {
|
||||
for (key of Object.keys(entry)) {
|
||||
const val = entry[key];
|
||||
if (typeof val === "object" && !Array.isArray(val)) {
|
||||
dict[mainLang][key] = sortDict(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(DICT_PATH, JSON.stringify(dict, null, 2) + "\n");
|
Loading…
Reference in a new issue