Loading…

ICS Calendar Parser

Most home-grown ICS readers skip RFC 5545 line folding entirely, and it is the one detail that quietly breaks them on real-world files. Any property line longer than 75 octets - which a normal-length SUMMARY on an economic release or a multi-word holiday name reaches easily - gets split across multiple physical lines by the exporting calendar tool, and every continuation line starts with exactly one space or tab that must be stripped before the value means anything. A parser that reads each physical line as one property either truncates that event's title at the fold point or, worse, treats the continuation line as if it were its own unrelated property. This library unfolds the whole file as its own explicit first pass (IcsUnfoldLines) before any property parsing happens at all, so folded and unfolded input produce identical results. Once unfolded, IcsParseLines scans for BEGIN:VEVENT / END:VEVENT blocks and reads UID, SUMMARY, LOCATION, DTSTART and DTEND out of each one, un-escaping the small set of RFC 5545 text escapes (\n, \,, \;, \\) that SUMMARY/LOCATION commonly carry. DTSTART/DTEND are parsed from both the DATE-TIME form (20240115T093000Z) and the all-day DATE form (DTSTART;VALUE=DATE:20240115), setting an allDay flag in the latter case so a caller does not mistake midnight-UTC for a real scheduled time. Notes and limitations - No timezone database. A DTSTART/DTEND carrying a TZID parameter (DTSTART;TZID=America/New_York:...) is parsed as the literal local time written in the value, with no offset conversion applied - hasTzid is set on the event so a caller can detect this case and apply its own known offset if the exact UTC instant matters. A trailing "Z" (UTC) DATE-TIME is parsed correctly since it needs no timezone lookup at all. - Recurring events (RRULE) are not expanded - each VEVENT block becomes exactly one IcsEvent representing its own DTSTART/DTEND, not the full series of occurrences a recurrence rule would generate. - VALARM, VTIMEZONE and any other block types are skipped entirely; only VEVENT content is extracted. - IcsSplitProperty splits each property line at its first colon. This is correct for every property this parser reads (none of UID, SUMMARY, LOCATION, DTSTART, DTEND ever place a colon inside a parameter value in practice), but a more exotic property with a colon-bearing parameter value would not round-trip correctly - not a concern for the five properties this library actually extracts. - IcsParseFile assumes the input file is written in a single-byte ASCII/ Latin-1-compatible encoding (FILE_ANSI); a UTF-8 calendar with non-ASCII event titles may render those specific characters incorrectly, though parsing structure (BEGIN/END/property boundaries) is unaffected.

Script · MT4 · v1.0 · Free

About ICS Calendar Parser

ICS Calendar Parser is a script for MetaTrader 4. MQL source code included.

Files in the download: IcsCalendarParser.mqh, IcsCalendarParser.txt, IcsCalendarParserDemo.mq4.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Trading Sessions · News Trading · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria