Support for time periods and binary data encoding/decoding with base64 operations. ICAL.js provides classes for handling iCalendar period values and binary data attachments.
Represents iCalendar period values (start time + end time OR duration).
/**
* Period constructor
* @param {Object} data - Period data
* @param {ICAL.Time} data.start - Period start time
* @param {ICAL.Time} data.end - Period end time (mutually exclusive with duration)
* @param {ICAL.Duration} data.duration - Period duration (mutually exclusive with end)
*/
class ICAL.Period {
constructor(data);
// Properties
start: ICAL.Time; // Period start time
end: ICAL.Time; // Period end time (if specified)
duration: ICAL.Duration; // Period duration (if specified)
readonly icaltype: string; // Always "period"
}/**
* Parse period from iCalendar string
* @param {string} str - Period string
* @returns {ICAL.Period} Parsed period
*/
static fromString(str);
/**
* Create period from data object
* @param {Object} data - Period data
* @returns {ICAL.Period} New period
*/
static fromData(data);/**
* Get or calculate duration
* @returns {ICAL.Duration} Period duration
*/
getDuration();
/**
* Get or calculate end time
* @returns {ICAL.Time} Period end time
*/
getEnd();
/**
* Convert to string representation
* @returns {string} String representation
*/
toString();
/**
* Convert to iCalendar string format
* @returns {string} iCalendar formatted period
*/
toICALString();Represents binary data with base64 encoding/decoding support.
/**
* Binary constructor
* @param {string} value - Binary data (base64 encoded)
*/
class ICAL.Binary {
constructor(value);
// Properties
value: string; // Binary value (base64 encoded)
readonly icaltype: string; // Always "binary"
}/**
* Create Binary instance from string
* @param {string} str - Base64 encoded string or raw string
* @returns {ICAL.Binary} New Binary instance
*/
static fromString(str: string): ICAL.Binary;/**
* Base64 decode the current value
* @returns {string} Decoded binary data
*/
decodeValue(): string;
/**
* Base64 encode value and set as current value
* @param {string} value - Raw binary data to encode
*/
setEncodedValue(value: string): void;
/**
* Get binary value
* @returns {string} Base64 encoded value
*/
toString(): string;Usage Examples:
const ICAL = require('ical.js');
// Create period with start and end times
const startTime = new ICAL.Time({
year: 2023, month: 6, day: 15,
hour: 10, minute: 0
});
const endTime = new ICAL.Time({
year: 2023, month: 6, day: 15,
hour: 12, minute: 0
});
const period1 = new ICAL.Period({
start: startTime,
end: endTime
});
console.log(period1.getDuration().hours); // 2
// Create period with start and duration
const duration = new ICAL.Duration({ hours: 3 });
const period2 = new ICAL.Period({
start: startTime,
duration: duration
});
console.log(period2.getEnd().hour); // 13
// Parse from string
const parsed = ICAL.Period.fromString('20230615T100000Z/20230615T120000Z');
console.log(parsed.start.toString()); // "2023-06-15T10:00:00Z"
// Work with binary data
const binary = new ICAL.Binary('SGVsbG8gV29ybGQ='); // "Hello World" in base64
console.log(binary.decodeValue()); // "Hello World"
// Create from string
const binaryFromString = ICAL.Binary.fromString('SGVsbG8gV29ybGQ=');
console.log(binaryFromString.decodeValue()); // "Hello World"
// Encode new data
binary.setEncodedValue('Test Data');
console.log(binary.value); // Base64 encoded "Test Data"