date-fns#endOfMonth TypeScript Examples
The following examples show how to use
date-fns#endOfMonth.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CashSplitService.ts From cashcash-desktop with MIT License | 6 votes |
async computeSplitSumOfTheMonth(
graphSplitList: GraphSplit[],
transactionDate: Date,
cashCurrency: CashCurrency,
cashAccountTree: CashAccount[],
): Promise<Map<number, GraphSplit>> {
const transactionDateFrom: Date = startOfMonth(transactionDate);
const transactionDateTo: Date = endOfMonth(transactionDate);
// Filter
const grahSplitListFiltered = graphSplitList.filter(
(item) =>
item.transactionDate >= transactionDateFrom &&
item.transactionDate <= transactionDateTo,
);
// Calculate leaf sum
const graphSplitMap = GraphUtils.reduceToMapOfOneCurrency(grahSplitListFiltered);
// Calculate branch sum
this.sumTree(cashAccountTree, cashCurrency, graphSplitMap);
return graphSplitMap;
}
Example #2
Source File: CashSplitService.ts From cashcash-desktop with MIT License | 6 votes |
async computeSplitSumOfTheMonthNew(
graphSplitList: GraphSplit[],
transactionDate: Date,
wipBudgetSheet: GraphSplitExtended | null,
): Promise<InOutSplitMap> {
const transactionDateFrom: Date = startOfMonth(transactionDate);
const transactionDateTo: Date = endOfMonth(transactionDate);
if (!wipBudgetSheet) {
return { inMap: new Map(), outMap: new Map() };
}
// Filter
const grahSplitListFiltered = graphSplitList.filter(
(item) =>
item.transactionDate >= transactionDateFrom &&
item.transactionDate <= transactionDateTo &&
item.accountId === wipBudgetSheet.accountId,
);
// Calculate leaf sum
const graphSplitMap = GraphUtils.reduceToInOutMapOfOneCurrency(grahSplitListFiltered);
return graphSplitMap;
}
Example #3
Source File: calendarEvents.ts From matx-angular with MIT License | 6 votes |
public events: any[] = [{
_id: '100',
start: subDays(startOfDay(new Date()), 1),
end: addDays(new Date(), 1),
title: 'A 3 day event',
color: this.colors.red
}, {
_id: '101',
start: startOfDay(new Date()),
title: 'An event with no end date',
color: this.colors.yellow
}, {
_id: '102',
start: subDays(endOfMonth(new Date()), 3),
end: addDays(endOfMonth(new Date()), 3),
title: 'A long event that spans 2 months',
color: this.colors.blue
}, {
_id: '103',
start: addHours(startOfDay(new Date()), 2),
end: new Date(),
title: 'A draggable and resizable event',
color: this.colors.yellow,
resizable: {
beforeStart: true,
afterEnd: true
},
draggable: true
}];
Example #4
Source File: MonthlyCalendar.tsx From react-calendar with MIT License | 6 votes |
MonthlyCalendar = ({
locale,
currentMonth,
onCurrentMonthChange,
children,
}: Props) => {
let monthStart = startOfMonth(currentMonth);
let days = eachDayOfInterval({
start: monthStart,
end: endOfMonth(monthStart),
});
return (
<MonthlyCalendarContext.Provider
value={{
days,
locale,
onCurrentMonthChange,
currentMonth: monthStart,
}}
>
{children}
</MonthlyCalendarContext.Provider>
);
}
Example #5
Source File: DayPicker.tsx From symphony-ui-toolkit with Apache License 2.0 | 5 votes |
focusOnlyEnabledCell(
date: Date,
action: 'next' | 'previous',
maxStepCheck: number,
needToChangeMonth = true
) {
const { locale } = this.props;
const index = date.getDate();
if (index) {
if (this.dayPicker) {
const enabledCell = this.getEnabledCell(index, action, maxStepCheck);
if (enabledCell) {
enabledCell.focus();
} else {
if (needToChangeMonth) {
// when called through arrow navigation
// when changing month, focus the first available date, if exists
const step = action === 'next' ? 1 : -1;
const nextMonth = addMonths(date, step);
this.setState({ currentMonth: nextMonth }, () => {
// we need to use the callback to be sure the date picker is re-rendered with the new month
const index = action === 'next' ? 1 : endOfMonth(nextMonth).getDate();
const enabledCell = this.getEnabledCell(index, action, maxStepCheck);
if (enabledCell) {
enabledCell.focus();
} else {
// if all cell are disabled, focus the first day of month
this.focusCell(
getBoundedDay(startOfMonth(nextMonth), nextMonth, locale)
);
}
});
} else {
// when called through ARROWS navigation
this.focusCell(getBoundedDay(startOfMonth(date), date, locale));
}
}
}
}
}
Example #6
Source File: dateUtils.ts From ant-extensions with MIT License | 5 votes |
parseDate = (dt?: string, rounded?: "start" | "end"): ParsedDate => {
if (dt && isDate(dt)) {
return parseISO(dt);
} else if (dt && isDateLike(dt)) {
const parts = getDateParts(dt);
if (parts) {
const { part, op, diff } = parts;
const diffNum = parseInt(`${op}${diff}`, 10);
let date = startOfMinute(new Date());
switch (part) {
case DateParts.NOW:
return date;
case DateParts.DECADE:
if (rounded) {
date = (rounded === "start" ? startOfDecade : endOfDecade)(date);
}
return addYears(date, diffNum * 10);
case DateParts.YEAR:
if (rounded) {
date = (rounded === "start" ? startOfYear : endOfYear)(date);
}
return addYears(date, diffNum);
case DateParts.QUARTER:
if (rounded) {
date = (rounded === "start" ? startOfQuarter : endOfQuarter)(date);
}
return addQuarters(date, diffNum);
case DateParts.MONTH:
if (rounded) {
date = (rounded === "start" ? startOfMonth : endOfMonth)(date);
}
return addMonths(date, diffNum);
case DateParts.WEEK:
if (rounded) {
date = (rounded === "start" ? startOfWeek : endOfWeek)(date);
}
return addWeeks(date, diffNum);
case DateParts.DAY:
if (rounded) {
date = (rounded === "start" ? startOfDay : endOfDay)(date);
}
return addDays(date, diffNum);
case DateParts.HOUR:
if (rounded) {
date = (rounded === "start" ? startOfHour : endOfHour)(date);
}
return addHours(date, diffNum);
case DateParts.MINUTE:
if (rounded) {
date = (rounded === "start" ? startOfMinute : endOfMinute)(date);
}
return addMinutes(date, diffNum);
}
}
}
return undefined;
}
Example #7
Source File: date.ts From ngx-gantt with MIT License | 5 votes |
endOfMonth(): GanttDate {
return new GanttDate(endOfMonth(this.value));
}
Example #8
Source File: MockService.ts From cashcash-desktop with MIT License | 4 votes |
async addMockData() {
if (process.env.NODE_ENV === 'development') {
const mockInputArray = [
{
outAccount: i18n.t('Wages and salarie'),
inAccount: i18n.t('Checking account'),
amount: 1150,
transactionDay: 3,
},
{
outAccount: i18n.t('Cash gifts received'),
inAccount: i18n.t('Checking account'),
amount: 80,
probablity: 0.1,
valueVariability: 80 * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Clothing'),
amount: 1566 / 12,
probablity: 0.5,
valueVariability: (1566 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Footwear'),
amount: 391 / 12,
probablity: 0.3,
valueVariability: (391 / 12) * 0.8,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Other clothing products and services'),
amount: 221 / 12,
probablity: 0.3,
valueVariability: (221 / 12) * 0.99,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('School books and supplies'),
amount: 56 / 12,
probablity: 0.8,
valueVariability: (56 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Tuition'),
amount: 798 / 12,
probablity: 0.3,
valueVariability: (798 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Television/cable services'),
amount: 672 / 12,
valueVariability: 672 / 12,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Musical instruments'),
amount: 33 / 12,
probablity: 0.2,
valueVariability: (33 / 12) * 0.8,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Video game and services'),
amount: 14 / 12,
probablity: 0.4,
valueVariability: (14 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Streaming video services'),
amount: 50 / 12,
probablity: 0.8,
valueVariability: (50 / 12) * 1,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Streaming audio services'),
amount: 11 / 12,
probablity: 0.8,
valueVariability: (11 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Television and sound equipments'),
amount: 89 / 12,
probablity: 0.8,
valueVariability: (89 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Video game and services'),
amount: 43 / 12,
probablity: 0.8,
valueVariability: (43 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Sporting events'),
amount: 50 / 12,
probablity: 0.2,
valueVariability: (50 / 12) * 0.9,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Sport/Gym subscription'),
amount: 198 / 12,
probablity: 0.8,
valueVariability: (198 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Recreational lessons'),
amount: 113 / 12,
probablity: 0.8,
valueVariability: (113 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Play, theater, opera'),
amount: 66 / 12,
probablity: 0.8,
valueVariability: (66 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Movies'),
amount: 48 / 12,
probablity: 0.8,
valueVariability: (48 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Parks or museums'),
amount: 26 / 12,
probablity: 0.8,
valueVariability: (26 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Photographic equipment'),
amount: 40 / 12,
probablity: 0.8,
valueVariability: (40 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Pet food'),
amount: 219 / 12,
probablity: 0.8,
valueVariability: (219 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Pet purchase, supplies, medicine'),
amount: 150 / 12,
probablity: 0.8,
valueVariability: (150 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Pet services'),
amount: 66 / 12,
probablity: 0.8,
valueVariability: (66 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Vet services'),
amount: 225 / 12,
probablity: 0.8,
valueVariability: (225 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Toys, arts and crafts'),
amount: 148 / 12,
probablity: 0.8,
valueVariability: (148 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('E-Books'),
amount: 24 / 12,
probablity: 0.8,
valueVariability: (24 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Newspapers/Magazines'),
amount: 53 / 12,
probablity: 0.8,
valueVariability: (53 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Bar'),
amount: 289 / 12,
probablity: 0.8,
valueVariability: (289 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Market'),
amount: 1200 / 12,
probablity: 0.8,
valueVariability: (1200 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Restaurant'),
amount: 3458 / 12,
probablity: 0.8,
valueVariability: (3458 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Supermarket'),
amount: 3200 / 12,
probablity: 0.8,
valueVariability: (3200 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Drugs'),
amount: 483 / 12,
probablity: 0.8,
valueVariability: (483 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Commercial health insurance'),
amount: 662 / 12,
probablity: 0.8,
valueVariability: (662 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Medical services'),
amount: 1566 / 12,
probablity: 0.8,
valueVariability: (1566 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Medical supplies'),
amount: 171 / 12,
probablity: 0.8,
valueVariability: (171 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Furniture'),
amount: 2024 / 12,
probablity: 0.8,
valueVariability: (2024 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Other household expenses'),
amount: 1050 / 12,
probablity: 0.8,
valueVariability: (1050 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Medical services'),
amount: 908 / 12,
probablity: 0.8,
valueVariability: (908 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Babysitting'),
amount: 100 / 12,
probablity: 0.8,
valueVariability: (100 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Insurance (Housing)'),
amount: 467 / 12,
probablity: 0.8,
valueVariability: (467 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Repair commodities (Housing)'),
amount: 26 / 12,
probablity: 0.8,
valueVariability: (26 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Repair services (Housing)'),
amount: 55 / 12,
probablity: 0.8,
valueVariability: (55 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Rent'),
amount: 4057 / 12,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Electricity'),
amount: 1496 / 12,
probablity: 0.8,
valueVariability: (1496 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Natural gas'),
amount: 409 / 12,
probablity: 0.8,
valueVariability: (1566 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Garbage collection'),
amount: 162 / 12,
probablity: 0.8,
valueVariability: (162 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Water'),
amount: 445 / 12,
probablity: 0.8,
valueVariability: (445 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Bank service charges'),
amount: 25 / 12,
probablity: 0.8,
valueVariability: (25 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Personal care products'),
amount: 395 / 12,
probablity: 0.8,
valueVariability: (395 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Personal care services'),
amount: 372 / 12,
probablity: 0.8,
valueVariability: (372 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Gasoline and other fuels'),
amount: 2108 / 12,
probablity: 0.8,
valueVariability: (2108 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Vehicle maintenance'),
amount: 889 / 12,
probablity: 0.8,
valueVariability: (889 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Vehicle insurance'),
amount: 976 / 12,
probablity: 0.8,
valueVariability: (976 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Parking fees'),
amount: 56 / 12,
probablity: 0.8,
valueVariability: (56 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Tolls passes'),
amount: 48 / 12,
probablity: 0.8,
valueVariability: (48 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Airline fares'),
amount: 500 / 12,
probablity: 0.8,
valueVariability: (500 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Intercity bus/train fares'),
amount: 89 / 12,
probablity: 0.8,
valueVariability: (89 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Intracity bus/train/metro fares'),
amount: 211 / 12,
probablity: 0.8,
valueVariability: (211 / 12) * 0.5,
},
{
outAccount: i18n.t('Checking account'),
inAccount: i18n.t('Taxi fares'),
amount: 71 / 12,
probablity: 0.8,
valueVariability: (71 / 12) * 0.5,
},
];
const now = startOfMonth(new Date());
const nowMinus24month = addMonths(now, -24);
let currentMonth = now;
const cashAccountService = Container.get(CashAccountService);
const cashTransactionService = Container.get(CashTransactionService);
while (isAfter(currentMonth, nowMinus24month)) {
for (const oneMockInput of mockInputArray) {
if (!oneMockInput.probablity || Math.random() < oneMockInput.probablity) {
let transactionDate = new Date(currentMonth);
if (oneMockInput.transactionDay) {
transactionDate = setDate(transactionDate, oneMockInput.transactionDay);
} else {
transactionDate = faker.date.between(
startOfMonth(currentMonth),
endOfMonth(currentMonth),
);
}
let amount;
if (oneMockInput.valueVariability) {
const fromValue = Math.max(
1,
oneMockInput.amount - oneMockInput.valueVariability,
);
const toValue = oneMockInput.amount - oneMockInput.valueVariability;
amount = this.getRandomNumber(fromValue, toValue);
} else {
amount = oneMockInput.amount;
}
const inAccount = await cashAccountService.find(
oneMockInput.inAccount.toString(),
);
if (!inAccount) {
throw new Error(`Account not found: ${oneMockInput.inAccount}`);
}
const outAccount = await cashAccountService.find(
oneMockInput.outAccount.toString(),
);
if (!outAccount) {
throw new Error(`Account not found: ${oneMockInput.outAccount}`);
}
const flatCashTransaction: FlatCashTransaction = new FlatCashTransaction({
description: `${faker.commerce.product()} from ${faker.company.companyName()}`,
detail: faker.lorem.sentence(3),
transactionDate,
currency: inAccount.currency,
amount,
inAccount,
outAccount,
type:
inAccount.type === CashAccountType.ASSET
? CashTransactionType.INCOME
: CashTransactionType.EXPENSE,
});
await cashTransactionService.save(flatCashTransaction);
// tslint:disable-next-line:no-console
console.log('Transaction created');
}
}
currentMonth = addMonths(currentMonth, -1);
}
}
}