date-fns#isSameYear TypeScript Examples
The following examples show how to use
date-fns#isSameYear.
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: case_list.tsx From j3pz-web with MIT License | 6 votes |
private getTime = (date: string) => {
if (!date) return '';
const now = new Date();
const updateTime = new Date(date);
if (isSameDay(now, updateTime)) {
return format(updateTime, 'HH:mm');
}
if (isSameYear(now, updateTime)) {
return format(updateTime, 'MM月dd日 HH:mm');
}
return format(updateTime, 'yyyy年MM月dd日 HH:mm');
};
Example #2
Source File: CashGraphService.ts From cashcash-desktop with MIT License | 4 votes |
async generateActivityGraph(
parameters: TransactionParameters,
splitList: GraphSplitExtended[],
accountMap: Map<number, CashAccount>,
currencyMap: Map<number, CashCurrency>,
): Promise<EChartOption> {
// Filter
const graphSplitList = GraphUtils.keepOneTransaction(splitList);
let activitySplitList = GraphUtils.convertToActivitySplit(graphSplitList);
activitySplitList = GraphUtils.reduceByDay(activitySplitList);
const serieListTemplate = {
type: 'heatmap',
coordinateSystem: 'calendar',
itemStyle: {
normal: {
color: '#ddb926',
},
},
label: {
normal: {
show: true,
formatter: '{b}',
},
},
};
const calendarTemplate: EChartOption.Calendar = {
width: '80%',
left: 'center',
range: [
DateUtils.formatDate(parameters.transactionDateFrom!),
DateUtils.formatDate(parameters.transactionDateTo!),
],
splitLine: {
show: true,
lineStyle: {
color: '#c1c1c1',
width: 1,
type: 'solid',
},
},
itemStyle: {
borderWidth: 5,
borderColor: '#fff',
},
yearLabel: {
formatter: isSameYear(
parameters.transactionDateFrom!,
parameters.transactionDateTo!,
)
? '{start}'
: '{start} - {end}',
},
dayLabel: {
align: 'right',
firstDay: 1, // start on Monday
nameMap: i18n.locale === 'en' ? 'en' : ['D', 'L', 'M', 'M', 'J', 'V', 'S'],
},
};
const visualMapTemplate: EChartOption.VisualMap = {
calculable: true,
orient: 'horizontal',
left: 'center',
textStyle: {
color: '#000',
fontWeight: 'bold',
},
realtime: false,
};
return {
series: [
{
...serieListTemplate,
calendarIndex: 0,
name: 'by amount',
data: activitySplitList.map((o) => [o.stringTransactionDate, o.amount]),
},
{
...serieListTemplate,
calendarIndex: 1,
name: 'by nb of transactions',
data: activitySplitList.map((o) => [
o.stringTransactionDate,
o.nbOfTransactions,
]),
},
],
tooltip: {
position: 'top',
formatter: (p: any) => {
const value =
p.seriesName === 'by amount'
? PrintUtils.printAmount(
'' + p.data[1],
+activitySplitList[0].currencyId,
currencyMap,
)
: p.data[1];
const dateParsed = parse(p.data[0], 'yyyy-MM-dd', new Date());
const dateString = DateUtils.formatHumanDate(dateParsed);
const dateStringWithUpperCase = StringUtils.toUpperCaseFirstLetter(dateString);
return dateStringWithUpperCase + ': ' + value;
},
},
visualMap: [
{
...visualMapTemplate,
top: 20,
seriesIndex: 0,
max:
activitySplitList.length > 0
? _.maxBy(activitySplitList, (o) => o.amount)!.amount
: 0,
text: ['', i18n.t('Amount per day').toString()],
formatter:
activitySplitList.length > 0
? '{value}' + currencyMap.get(splitList[0].currencyId)!.symbol
: '{value}',
},
{
...visualMapTemplate,
top: 270,
seriesIndex: 1,
max:
activitySplitList.length > 0
? _.maxBy(activitySplitList, (o) => o.nbOfTransactions)!
.nbOfTransactions
: 0,
text: ['', i18n.t('Number of transactions per day').toString()],
},
],
calendar: [
{
...calendarTemplate,
top: 90,
},
{
...calendarTemplate,
top: 340,
},
],
color: GraphUtils.getDefaultColorPalette(),
};
}