@@ -11,15 +11,19 @@ function id2uuid(id, day) {
1111 if ( day ) {
1212 id += day ;
1313 }
14- return uuid ( id , NAMESPACE ) + ' @furkot.com' ;
14+ return ` ${ uuid ( id , NAMESPACE ) } @furkot.com` ;
1515}
1616
1717function ts2date ( ts ) {
1818 // remove dashes and colons and strip milliseconds
1919 return new Date ( ts ) . toISOString ( ) . replace ( / [ - : ] / g, '' ) . slice ( 0 , - 5 ) ;
2020}
2121
22- export default function * ical ( { metadata, routes } ) {
22+ function tzid ( property , tz ) {
23+ return tz ? `${ property } ;TZID=${ tz } ` : property ;
24+ }
25+
26+ export default function * ical ( { metadata, routes, options = { } } ) {
2327 const dtstamp = ts2date ( Date . now ( ) ) ;
2428
2529 yield * property ( 'BEGIN' , 'VCALENDAR' ) ;
@@ -40,8 +44,9 @@ export default function* ical({ metadata, routes }) {
4044 yield * property ( 'URL' , step . url ) ;
4145 yield * property ( 'LOCATION' , step . address ) ;
4246 yield * property ( 'GEO' , [ step . coordinates . lat , step . coordinates . lon ] , formatArray ) ;
43- yield * property ( 'DTSTART' , ts2date ( step . arrival_time ) ) ;
44- yield * property ( 'DTEND' , ts2date ( step . departure_time ) ) ;
47+ const tz = options . tzid && step . timezone ?. name ;
48+ yield * property ( tzid ( 'DTSTART' , tz ) , ts2date ( step . arrival_time ) ) ;
49+ yield * property ( tzid ( 'DTEND' , tz ) , ts2date ( step . departure_time ) ) ;
4550 yield * property ( 'END' , 'VEVENT' ) ;
4651 }
4752 yield * property ( 'END' , 'VCALENDAR' ) ;
0 commit comments