Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added parsing for alarms #299

Merged
merged 7 commits into from
Feb 27, 2024
Merged

added parsing for alarms #299

merged 7 commits into from
Feb 27, 2024

Conversation

jonnytest1
Copy link
Contributor

note1: test2.ics has a VALARM outside of any events (which might be invalid)

result:

{
   type: 'VEVENT'
   ...
   alarms:{
      type:VALARM
      ...
   }
}
  type Task = {
      type:"VEVENT"
      alarms?:Array<Alarm>
  }

@jonnytest1
Copy link
Contributor Author

(if note 1 is solved by addressing the test data i can remove te par.type=="VEVENT" check

@jens-maus
Copy link
Owner

(if note 1 is solved by addressing the test data i can remove te par.type=="VEVENT" check

Please adapt test2.ics yourself as being part of this PR.

@jonnytest1
Copy link
Contributor Author

one second ill quickly chekc the other files

@jonnytest1
Copy link
Contributor Author

jonnytest1 commented Jan 31, 2024

ok - i wonder if i should also add some "calender" methods for alarms 🤔
I did write a parser for it after all (mostly just integrating the "trigger" property a bit)

oh judging from the example data my implementation would be missing some cases 🤔

class EventAlarm implements AlarmProvider {

  type: "VALARM"
  trigger: string

  action: "DISPLAY"


  timeOffset: number


  relative: boolean

  constructor(alarmConfig) {
    Object.assign(this, alarmConfig)


    this.calculateTimeOffset()
  }
  calculateTimeOffset() {
    const triggerMAtch = this.trigger.match(/(?<relative>-)?P(?<days>\d+)D.*?T?((?<hours>\d+)H)?((?<minutes>\d+)M)?((?<seconds>\d+)S)?/)
    if (!triggerMAtch) {
      console.error("invalid regex parsing TRIGGER for alarm ", this.trigger)
      return
    }

    this.relative = !!triggerMAtch.groups.relative
    const days = +triggerMAtch.groups.days
    const hours = +(triggerMAtch.groups.hours ?? 0)
    const minutes = +(triggerMAtch.groups.minutes ?? 0)
    const seconds = +(triggerMAtch.groups.seconds ?? 0)


    this.timeOffset = 0
    this.timeOffset += seconds * SECOND
    this.timeOffset += minutes * MINUTE
    this.timeOffset += hours * HOUR
    this.timeOffset += days * DAY
  }

  getDateForEventInstance(start_or_rrule_date: Date) {
    if (!this.relative) {
      const copy = new Date(start_or_rrule_date);
      copy.setHours(0)
      copy.setMinutes(0)
      copy.setSeconds(0)

      const absoulte = new Date(+copy + this.timeOffset)
      return absoulte
    }
    return new Date(start_or_rrule_date.valueOf() - this.timeOffset);
  }

}

@jens-maus
Copy link
Owner

one second ill quickly chekc the other files

Are you sure that VALARM outside VEVENT is invalid? I wonder because all these test.ics files are certainly not made/generated by hand. Thus, there might be ical applications out there having generated these ics files and I wonder who is wrong? They or you?

@jonnytest1
Copy link
Contributor Author

jonnytest1 commented Jan 31, 2024

i foudn spec - https://www.kanzaki.com/docs/ical/valarm.html 🤔 so i guess i should add a VTODO case as well
image

@titanism
Copy link

This would be amazing to have!

@jonnytest1
Copy link
Contributor Author

jonnytest1 commented Feb 13, 2024

i noticed the event alarm class is missing a few trigger formats so i dont think it should be part of this pr

@jens-maus jens-maus merged commit 6a5175e into jens-maus:master Feb 27, 2024
15 checks passed
@jonnytest1
Copy link
Contributor Author

oh i missed the d.ts file 🥲

@jens-maus
Copy link
Owner

then please go ahead and submit another PR because I did not yet release a new node-ical version.

@jonnytest1
Copy link
Contributor Author

sujal pushed a commit to Metacrafters/node-ical that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants