Comments (3)
The code above doesn't work anymore since the api has changed.
Just in case somebody has the same issue, here my refiner that should work with the latest version (1.0.x).
function isPastDate({year, month, day}, ref) {
let refDay = ref.getDate();
let refMonth = ref.getMonth() + 1;
let refYear = ref.getFullYear();
if(refYear > year) {
return true;
}
if(refMonth > month){
return true;
}
if(refDay > day){
return true;
}
return false;
}
var PreferPastLastWeek = new chrono.Refiner();
PreferPastLastWeek.refine = function(text, results) {
results.forEach(function(result) {
if (result.start.isCertain('weekday') && !result.start.isCertain('day')) {
if(isPastDate(result.start.impliedValues, result.ref)) {
result.start.imply('day', result.start.impliedValues.day + 7)
}
}
});
return results;
};
chrono.casual.refiners.push(PreferPastLastWeek);
chrono.strict.refiners.push(PreferPastLastWeek);
Anyway thanks @wanasit for this awesome lib!
from chrono.
Actually, you can customize Chrono with some plug-in called refiners
.
(It's currently undocumented. Sorry that I didn't have time to do that recently)
var chrono = require('chromo');
var _chrono = new chrono(); //Let's keep the global chrono uncustomized
_chrono.parseDate('Thursday', new Date(2013,11,2))
// Thu Dec 05 2013 12:00:00 GMT+0900 (JST)
_chrono.refiners.PreferPastLastWeek = {
refine: function(text, results) {
results.forEach(function(result){
// Check and modify the result
if( result.start.isCertain('dayOfWeek') && !result.start.isCertain('day')){
result.start.imply('day', result.start.day - 7)
}
})
return results;
}
}
_chrono.parseDate('Thursday', new Date(2013,11,2))
// Thu Nov 28 2013 12:00:00 GMT+0900 (JST)
You can define plug-in chrono.refiners.XXX
with an object with function refine
(receives text and an array of parsed results as arguments, and returns array of modified results). As its name, you can refine the parsing results with your custom rules.
Hope this helps
from chrono.
Right on! Can't wait to try it out :) 👍
from chrono.
Related Issues (20)
- `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 5
- Timezone parsing reference not working as expected with `forwardDate: true` specified HOT 1
- Incorrect Parsing of "the money" as a Date HOT 1
- v1.x isCertain returns unexpected values HOT 1
- Wrong result for a simple case HOT 2
- [BUG] Month and day not recognized HOT 2
- Incorrect Year in Date Parsing 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.