-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
relative day and month expressions #31
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,11 +135,11 @@ DurationString | |
DurationAbbrev | ||
= "ms" | ||
/ "s" | ||
/ "m" | ||
/ "m" !"o" | ||
/ "h" | ||
/ "d" | ||
/ "w" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove stray spaces introduced here and elsewhere |
||
CalendarUnit | ||
= string:CalendarString "s" { | ||
return string; | ||
|
@@ -159,6 +159,33 @@ CalendarAbbrev | |
/ "M" | ||
/ "y" | ||
|
||
Weekday | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much terser way to specify these strings:
(this would also match MON, but I don't think that is a bad thing) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weekday --> WeekdayString |
||
= ( "monday" / "Monday" / "Mon" / "mon" ) { return 1 } | ||
/ ( "tuesday" / "Tuesday" / "Tue" / "tue") { return 2 } | ||
/ ( "wednesday"/ "Wednesday" / "Wed" / "wed") { return 3 } | ||
/ ( "thursday"/ "Thursday" / "Thu" / "thu") { return 4 } | ||
/ ( "friday"/ "Friday" / "Fri" / "fri") { return 5 } | ||
/ ( "saturday"/ "Saturday" / "Sat" / "sat") { return 6 } | ||
/ ( "sunday"/ "Sunday" / "Sun" / "sun") { return 7 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to return a standardized weekday literal for all flavors of match, eg, "sunday" rather than 7, and convert this to a numeric offset in the generator using momentjs. But in any event, sunday's offset here should be 0 to agree with momentjs's indexing. |
||
|
||
Month | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same suggestions as for Weekday. |
||
= ( "january"/ "January"/ "jan"/ "Jan") { return 1 } | ||
/ ("february"/ "February"/ "feb"/ "Feb") { return 2 } | ||
/ ("march"/ "March"/ "mar"/ "Mar") { return 3 } | ||
/ ("april"/ "April"/ "apr"/ "Apr") { return 4 } | ||
/ ("may"/ "May") { return 5 } | ||
/ ("june"/ "June"/ "jun"/ "Jun") { return 6 } | ||
/ ("july"/ "July"/ "jul"/ "Jul") { return 7 } | ||
/ ("august"/ "August"/ "aug"/ "Aug") { return 8 } | ||
/ ("september"/ "September"/ "sep"/ "Sep") { return 9 } | ||
/ ("october"/ "October"/ "oct"/ "Oct") { return 10 } | ||
/ ("november"/ "November"/ "nov"/ "Nov") { return 11 } | ||
/ ("december"/ "December"/ "dec"/ "Dec") { return 12 } | ||
|
||
|
||
Unit = CalendarUnit / DurationUnit | ||
|
||
|
||
HumanDuration | ||
= num:Integer? _ unit:CalendarUnit { | ||
return { | ||
|
@@ -246,26 +273,16 @@ CalendarExpression | |
valueType: "moment" | ||
}; | ||
} | ||
/ "this" _ unit:( CalendarUnit / DurationUnit ) { | ||
/ "next" _ unit:Unit { | ||
var wdawd | ||
return { | ||
type: "CalendarExpression", | ||
valueType: "moment", | ||
direction: "down", | ||
unit: unit, | ||
expression: { | ||
type: "NowLiteral" | ||
} | ||
}; | ||
} | ||
/ "last" _ unit:( CalendarUnit / DurationUnit ) { | ||
return { | ||
type: "CalendarExpression", | ||
valueType: "moment", | ||
direction: "down", | ||
unit: unit, | ||
unit: unit.unit, | ||
expression: { | ||
type: "BinaryExpression", | ||
operator: "-", | ||
operator: "+", | ||
left: { | ||
type: "NowLiteral" | ||
}, | ||
|
@@ -277,15 +294,75 @@ CalendarExpression | |
} | ||
}; | ||
} | ||
/ "next" _ unit:( CalendarUnit / DurationUnit ) { | ||
/ month: Month { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the month/weekday handling in last/this/next expressions is essentially the same math whether months or weekdays are involved (eg, "this" means startof year/week + month/day offset), and ought to be collapsed as was done for the existing last/this/next calendar expressions. This will also simplify the generator. |
||
return { | ||
modifier: "", | ||
type: "monthLiteration", | ||
value: month | ||
} | ||
} | ||
|
||
/ "next" _ month: Month { | ||
return { | ||
modifier: "next", | ||
type: "monthLiteration", | ||
value: month | ||
} | ||
} | ||
|
||
/ "this" _ month: Month { | ||
return { | ||
modifier: "this", | ||
type: "monthLiteration", | ||
value: month | ||
} | ||
} | ||
/ weekday: Weekday { | ||
return { | ||
modifier: "", | ||
type: "weekdayLiteration", | ||
value: weekday | ||
} | ||
} | ||
|
||
/ "next" _ weekday: Weekday { | ||
return { | ||
modifier: "next", | ||
type: "weekdayLiteration", | ||
value: weekday | ||
} | ||
} | ||
|
||
/ "this" _ weekday: Weekday { | ||
return { | ||
modifier: "this", | ||
type: "weekdayLiteration", | ||
value: weekday | ||
} | ||
} | ||
|
||
|
||
|
||
/ "this" _ unit:Unit { | ||
return { | ||
type: "CalendarExpression", | ||
valueType: "moment", | ||
direction: "down", | ||
unit: unit, | ||
expression: { | ||
type: "NowLiteral" | ||
} | ||
}; | ||
} | ||
/ "last" _ unit:Unit { | ||
return { | ||
type: "CalendarExpression", | ||
valueType: "moment", | ||
direction: "down", | ||
unit: unit, | ||
expression: { | ||
type: "BinaryExpression", | ||
operator: "+", | ||
operator: "-", | ||
left: { | ||
type: "NowLiteral" | ||
}, | ||
|
@@ -297,6 +374,8 @@ CalendarExpression | |
} | ||
}; | ||
} | ||
|
||
|
||
/ unit:CalendarUnit _ "of" _ expr:MomentExpression { | ||
return { | ||
type: "CalendarExpression", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change, and the others added in subsequent commit, can be eliminated by including Weekday in CalendarUnit, so it is matched before DurationAbbrev, eg,