@shaivpidadi/trends-js
Version:
Google Trends API for Node.js
22 lines (21 loc) • 795 B
JavaScript
const formatDate = (date) => {
return date.toISOString().split('T')[0];
};
const formatTrendsDate = (date) => {
const pad = (n) => n.toString().padStart(2, '0');
const yyyy = date.getFullYear();
const mm = pad(date.getMonth() + 1);
const dd = pad(date.getDate());
const hh = pad(date.getHours());
const min = pad(date.getMinutes());
const ss = pad(date.getSeconds());
return `${yyyy}-${mm}-${dd}T${hh}\\:${min}\\:${ss}`;
};
const getDateRangeParam = (date) => {
const yesterday = new Date(date);
yesterday.setDate(date.getDate() - 1);
const formattedStart = formatTrendsDate(yesterday);
const formattedEnd = formatTrendsDate(date);
return `${formattedStart} ${formattedEnd}`;
};
export { formatDate, formatTrendsDate, getDateRangeParam };