Comments (2)
@zhouzi Sorry for my slow reply. As mentioned in #525, outputting format text for all supported conditions and locales would be challenging.
From what you explained, the problem is you want to recognize the casual reference date (e.g. today, tomorrow) to treat them differently. I think that a reasonable use-case and I found it surprisingly difficult to do it with the current API.
I think this problem could be solved by the parsing tag (#534). Introducing tags is an idea that I have been thinking about for debugging parsers, but I think it also fits your use-case. Could you take a look at #534 and give me some feedback?
from chrono.
This has been solved by #534, here's how our code looks like:
const getCasualText = (parsedComponents: ParsedComponents) => {
const tags = parsedComponents.tags();
const translations = [
['casualReference/today', 'Today'],
['casualReference/yesterday', 'Yesterday'],
['casualReference/tomorrow', 'Tomorrow'],
['casualReference/now', 'Now'],
];
for (const [tag, casualText] of translations) {
if (tags.has(tag)) return casualText;
}
return undefined;
};
With this function it's possible to convert a parsed date to the appropriate string (Today/Yesterday/Tomorrow/Now). We don't need to translate to other languages but it wouldn't be too hard to do if we ever need it:
const translations = {
"parser/ENCasualDateParser": [
['casualReference/today', 'Today'],
['casualReference/yesterday', 'Yesterday'],
['casualReference/tomorrow', 'Tomorrow'],
['casualReference/now', 'Now'],
],
// ...other parsers
};
It's worth noting that tags are not added for all locales at the time of writing, which is fine for our use case. But if someone needs more tags they might want to send a PR.
from chrono.
Related Issues (20)
- Adding a new language HOT 1
- Invalid parsing: from 01/21/2021 10:00 to 01/01/2023 07:00 HOT 1
- Information loss using timezone offset
- Invalid parsing: `08/08/2023, 09:15 AM to 08/29/2023, 09:15 AM` HOT 2
- `mon` and `monday` no longer recognized HOT 1
- Accept next tuesday +10 days HOT 4
- Question: auThursday eptember 28 12:00 PM parsed as Sat Oct 07 2023 12:00:00 HOT 2
- Main branch failing test. HOT 3
- Cannot parse Month and Year HOT 3
- Update in package.json structure and Language Customization Feature
- de locale in parse function HOT 2
- Results are sometimes off by one day when setting time in JST but calling from a different timezone HOT 5
- Error parsing of local time in the Common Log Format (06/Nov/2023:06:36:02 +0200) HOT 1
- Incorrect parsing of Chinese for 'tomorrow morning at 8am' HOT 2
- feat: add support to unix timestamp HOT 2
- Incorrect Recognition of "in [month]" pattern HOT 1
- How to tell if result needs the time or not? HOT 2
- parseDate is incorrect for these inputs HOT 4
- Timezone parsing reference not working as expected with `forwardDate: true` specified HOT 1
- Incorrect Parsing of "the money" as a Date HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chrono.