-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
63 lines (52 loc) · 1.9 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const n = require('nanakshahi')
const ics = require('ics')
const { writeFileSync } = require('fs')
const path = require('path')
const newDateFormat = (a) => {
return a.toISOString().split('T')[0].split('-').map(Number)
}
const formatNanakshahiDate = (gregorianDate) => {
const nDate = n.getNanakshahiDate(gregorianDate)
if (!nDate || !nDate.englishDate || !nDate.punjabiDate) return null
return {
en: `${nDate.englishDate.date} ${nDate.englishDate.monthName}`,
pa: `${nDate.punjabiDate.date} ${nDate.punjabiDate.monthName}`,
year: nDate.englishDate.year,
day: {
en: nDate.englishDate.day,
pa: nDate.punjabiDate.day
}
}
}
const calEvents = []
const currentYear = new Date().getFullYear()
const yearStart = new Date(currentYear, 0, 1)
const yearEnd = new Date(currentYear + 1, 11, 31)
const endTime = yearEnd.getTime()
for (let day = new Date(yearStart); day.getTime() <= endTime; day.setDate(day.getDate() + 1)) {
const currentDay = new Date(day)
const gurpurab = n.getGurpurabsForDay(currentDay)
const nDate = formatNanakshahiDate(currentDay)
for (const g in gurpurab) {
calEvents.push({
start: newDateFormat(currentDay),
title: gurpurab[g].en,
description: gurpurab[g].pa + (nDate ? `\n\nNanakshahi Date:\n${nDate.pa} ${nDate.year} NS` : ''),
categories: [gurpurab[g].type]
})
}
if (nDate) {
calEvents.push({
start: newDateFormat(currentDay),
duration: { days: 1 },
title: `${nDate.en} ${nDate.year} NS (${nDate.day.en})`,
description: `Nanakshahi Date:\n${nDate.en} ${nDate.year} NS (${nDate.day.en})\n${nDate.pa} ${nDate.year} NS (${nDate.day.pa})`,
categories: ['daily']
})
}
}
const { error, value } = ics.createEvents(calEvents)
if (error) throw error
const filePath = path.join(__dirname, '/nanakshahi.ics')
writeFileSync(filePath, value)
module.exports = { newDateFormat, formatNanakshahiDate }