Skip to content

Commit

Permalink
Refactor start and year end and show daily NS dates
Browse files Browse the repository at this point in the history
  • Loading branch information
janpreet committed Jan 26, 2025
1 parent 92038de commit 76ab25c
Show file tree
Hide file tree
Showing 3 changed files with 8,866 additions and 619 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# nanakshahi-ical
[![Nanakshahi iCal CI](https://github.com/janpreet/nanakshahi-ical/actions/workflows/main.yml/badge.svg)](https://github.com/janpreet/nanakshahi-ical/actions/workflows/main.yml)

This is a script that generates an ICS file for Nanakshahi dates and Sikh religious holidays.
This script generates an ICS file that includes both Nanakshahi calendar dates and Sikh religious holidays. Itdisplays:
- Daily Nanakshahi dates in both English and Punjabi.
- Day of the week in both languages.
- All Gurpurabs and historical events.
- Nanakshahi year (NS - Nanakshahi Samvat).

## Usage
### Apple Calendar
You can subscribe to this calendar from your Apple calendar by following these steps:

1. Open the Calendar app on your Mac.
Expand All @@ -13,5 +18,14 @@ You can subscribe to this calendar from your Apple calendar by following these s
5. Customize the settings for the calendar subscription, such as the name and color.
6. Click OK.

### Google Calendar
To add this calendar to Google Calendar:

1. Open Google Calendar
2. Click the "+" next to "Other calendars"
3. Select "From URL"
4. Enter [this URL](https://raw.githubusercontent.com/janpreet/nanakshahi-ical/main/nanakshahi.ics)
5. Click "Add calendar"

## Acknowledgments
This script is built on top of the [nanakshahi-js](https://github.com/Sarabveer/nanakshahi-js) library, which provides the necessary functions to calculate the Gurpurab dates.
This script is built on top of the [nanakshahi-js](https://github.com/Sarabveer/nanakshahi-js) library, which provides the necessary functions to calculate the Gurpurab dates and Nanakshahi calendar conversions.
70 changes: 43 additions & 27 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
const n = require('nanakshahi')
const ics = require('ics', './dist')
const {
writeFileSync
} = require('fs')
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 getGurpurab = (a) => {
return n.getGurpurabsForDay(a)
const formatNanakshahiDate = (gregorianDate) => {
const nDate = n.getNanakshahiDate(gregorianDate)
if (!nDate || !nDate.englishDate || !nDate.punjabiDate) return null

Check failure on line 13 in main.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
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 = []
let gurpurab = {}
const yearStart = new Date(new Date().getFullYear(), 0, 1)
const yearEnd = new Date(new Date().getFullYear(), 12, 0)
const day = yearStart
while (day.setDate(day.getDate() + 1) <= yearEnd) {
gurpurab = getGurpurab(day)

const currentYear = new Date().getFullYear()
const yearStart = new Date(currentYear, 0, 1)
const yearEnd = new Date(currentYear + 1, 11, 31)
const day = new Date(yearStart)

while (day <= yearEnd) {

Check failure on line 32 in main.js

View workflow job for this annotation

GitHub Actions / Lint

'day' is not modified in this loop

Check failure on line 32 in main.js

View workflow job for this annotation

GitHub Actions / Lint

'yearEnd' is not modified in this loop
const currentDay = new Date(day)
const gurpurab = n.getGurpurabsForDay(currentDay)
const nDate = formatNanakshahiDate(currentDay)

Check failure on line 36 in main.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
for (const g in gurpurab) {
calEvents.push({
start: newDateFormat(day),
start: newDateFormat(currentDay),
title: gurpurab[g].en,
description: gurpurab[g].pa,
description: gurpurab[g].pa + (nDate ? `\n\nNanakshahi Date:\n${nDate.pa} ${nDate.year} NS` : ''),
categories: [gurpurab[g].type]
})
}

Check failure on line 45 in main.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
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']
})
}

Check failure on line 55 in main.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
day.setDate(day.getDate() + 1)
}

const {
error,
value
} = ics.createEvents(calEvents)

if (error) {
console.log(error)
}
console.log(value)
const { error, value } = ics.createEvents(calEvents)
if (error) throw error

const filePath = path.join(__dirname, '/nanakshahi.ics')
writeFileSync(filePath, value)

module.exports = {
newDateFormat,
getGurpurab
}
module.exports = { newDateFormat, formatNanakshahiDate }

Check failure on line 65 in main.js

View workflow job for this annotation

GitHub Actions / Lint

Newline required at end of file but not found
Loading

0 comments on commit 76ab25c

Please sign in to comment.