-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
'until' template and improved 'starting' template #6927
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
6dd121f
4887baf
71f2945
6019dcd
50cc145
e32ee7f
511e766
77e9ed2
c499ee7
23f8700
0e7538a
332811b
351d416
00193a5
81f94e7
1f3df9e
bbec1c4
f7f9c3f
f84f9ab
5c1a175
8d7b1f1
8f48f8e
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 |
|---|---|---|
|
|
@@ -330,6 +330,10 @@ export class CategoryTemplateContext { | |
| // sort the template lines into regular template, goals, and remainder templates | ||
| if (templates) { | ||
| templates.forEach(t => { | ||
| // Skip expired templates (where month > until) | ||
| if (CategoryTemplateContext.isTemplateExpired(t, month)) { | ||
| return; | ||
| } | ||
| if ( | ||
| t.directive === 'template' && | ||
| t.type !== 'remainder' && | ||
|
|
@@ -441,6 +445,26 @@ export class CategoryTemplateContext { | |
| }); | ||
| } | ||
|
|
||
| private static isTemplateExpired(template: Template, month: string): boolean { | ||
|
||
| // Check if template hasn't started yet (if starting is set) | ||
| if ('starting' in template && template.starting) { | ||
| const startingMonth = template.starting.substring(0, 7); | ||
| if (monthUtils.differenceInCalendarMonths(month, startingMonth) < 0) { | ||
| return true; | ||
| } | ||
| } | ||
| // Check if template has expired (if until is set) | ||
| if ('until' in template && template.until) { | ||
| // Extract the month part if until is a full date (YYYY-MM-DD), otherwise use as-is (YYYY-MM) | ||
| const untilMonth = template.until.substring(0, 7); | ||
| // Return true if current month is after the until month | ||
| if (monthUtils.differenceInCalendarMonths(month, untilMonth) > 0) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private checkLimit(templates: Template[]) { | ||
| for (const template of templates.filter( | ||
| t => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,33 @@ | ||
| // https://peggyjs.org | ||
|
|
||
| expr | ||
| = template: template _ percentOf:percentOf category: name | ||
| { return { type: 'percentage', percent: +percentOf.percent, previous: percentOf.prev, category, priority: template.priority, directive: template.directive }} | ||
| / template: template _ amount: amount _ repeatEvery _ period: periodCount _ starting _ starting: date limit: limit? | ||
| { return { type: 'periodic', amount, period, starting, limit, priority: template.priority, directive: template.directive }} | ||
| / template: template _ amount: amount _ by _ month: month from: spendFrom? repeat: (_ repeatEvery _ repeat)? | ||
| = template: template _ percentOf:percentOf category: name starting: startingDate? until:until? | ||
| { return { type: 'percentage', percent: +percentOf.percent, previous: percentOf.prev, category, starting, until, priority: template.priority, directive: template.directive }} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| / template: template _ amount: amount _ repeatEvery _ period: periodCount _ starting: startingDate limit: limit? until: until? | ||
|
||
| { return { type: 'periodic', amount, period, starting, limit, until, priority: template.priority, directive: template.directive }} | ||
|
||
| / template: template _ amount: amount _ by _ month: month from: spendFrom? repeat: (_ repeatEvery _ repeat)? starting: startingDate? until: until? | ||
| { return { | ||
| type: from ? 'spend' : 'by', | ||
| amount, | ||
| month, | ||
| ...(repeat ? repeat[3] : {}), | ||
| from, | ||
| starting, | ||
| until, | ||
| priority: template.priority, directive: template.directive | ||
| }} | ||
| / template: template _ monthly: amount limit: limit? | ||
| { return { type: 'simple', monthly, limit, priority: template.priority, directive: template.directive }} | ||
| / template: template _ limit: limit | ||
| { return { type: 'simple', monthly: null, limit, priority: template.priority, directive: template.directive }} | ||
| / template: template _ schedule:schedule _ full:full? name:rawScheduleName modifiers:modifiers? | ||
| { return { type: 'schedule', name: name.trim(), priority: template.priority, directive: template.directive, full, adjustment: modifiers?.adjustment, adjustmentType: modifiers?.adjustmentType }} | ||
| / template: template _ remainder: remainder limit: limit? | ||
| { return { type: 'remainder', priority: null, directive: template.directive, weight: remainder, limit }} | ||
| / template: template _ 'average'i _ amount: positive _ 'months'i? modifiers:modifiers? | ||
| { return { type: 'average', numMonths: +amount, priority: template.priority, directive: template.directive, adjustment: modifiers?.adjustment, adjustmentType: modifiers?.adjustmentType }} | ||
| / template: template _ 'copy from'i _ lookBack: positive _ 'months ago'i limit:limit? | ||
| { return { type: 'copy', priority: template.priority, directive: template.directive, lookBack: +lookBack, limit }} | ||
| / template: template _ monthly: amount limit: limit? starting: startingDate? until: until? | ||
| { return { type: 'simple', monthly, limit, starting, until, priority: template.priority, directive: template.directive }} | ||
| / template: template _ limit: limit starting: startingDate? until: until? | ||
| { return { type: 'simple', monthly: null, limit, starting, until, priority: template.priority, directive: template.directive }} | ||
| / template: template _ schedule:schedule _ full:full? name:rawScheduleName modifiers:modifiers? starting: startingDate? until: until? | ||
| { return { type: 'schedule', name: name.trim(), priority: template.priority, directive: template.directive, full, adjustment: modifiers?.adjustment, adjustmentType: modifiers?.adjustmentType, starting, until }} | ||
| / template: template _ remainder: remainder limit: limit? starting: startingDate? until: until? | ||
| { return { type: 'remainder', priority: null, directive: template.directive, weight: remainder, limit, starting, until }} | ||
| / template: template _ 'average'i _ amount: positive _ 'months'i? modifiers:modifiers? starting: startingDate? until: until? | ||
| { return { type: 'average', numMonths: +amount, priority: template.priority, directive: template.directive, adjustment: modifiers?.adjustment, adjustmentType: modifiers?.adjustmentType, starting, until }} | ||
| / template: template _ 'copy from'i _ lookBack: positive _ 'months ago'i limit:limit? starting: startingDate? until: until? | ||
| { return { type: 'copy', priority: template.priority, directive: template.directive, lookBack: +lookBack, limit, starting, until }} | ||
| / goal: goal amount: amount { return {type: 'goal', amount: amount, priority: null, directive: goal }} | ||
|
|
||
| modifiers = _ '[' modifier:modifier ']' { return modifier } | ||
|
|
@@ -71,9 +73,10 @@ weeks = 'weeks'i | |
| by = 'by'i | ||
| of = 'of'i | ||
| repeatEvery = 'repeat'i _ 'every'i | ||
| starting = 'starting'i | ||
| startingDate = _ 'starting'i _ val: $(year '-' d d ('-' d d)?) { return val } | ||
| upTo = 'up'i _ 'to'i | ||
| hold = 'hold'i {return true} | ||
| until = _ 'until'i _ val: $(year '-' d d ('-' d d)?) { return val } | ||
| schedule = 'schedule'i { return text() } | ||
| full = 'full'i _ {return true} | ||
| priority = '-'i number: number {return number} | ||
|
|
||
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 is simpler then I would have thought. I was worried this would have to touch a lot of things to work.