@stacksjs/calendar-api 0.66.0 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +0,0 @@
1
- import type { CalendarLink } from '../types'
2
- import { useDateFormat } from '@stacksjs/browser'
3
-
4
- const dateFormat = 'YYYYMMDD'
5
- const timeFormat = 'YYYYMMDDThhmmss'
6
-
7
- export function generateGoogle(link: CalendarLink): string {
8
- // 20221020T170000Z/20221020T173000Z
9
- let url = 'https://calendar.google.com/calendar/render?action=TEMPLATE'
10
-
11
- const utcStartDateTime = convertTZ(link.from, 'UTC') // set timezone to UTC
12
- const utcEndDateTime = convertTZ(link.to, 'UTC') // set timezone to UTC
13
- const dateTimeFormat = link.allDay ? dateFormat : timeFormat
14
-
15
- url = `${url}&dates=${useDateFormat(utcStartDateTime, dateTimeFormat).value}/${
16
- useDateFormat(utcEndDateTime, dateTimeFormat).value
17
- }`
18
-
19
- if (link.timezone)
20
- url = `${url}&ctz=${link.timezone}`
21
-
22
- url = `${url}&text=${encodeURIComponent(link.title)}`
23
-
24
- if (link.description)
25
- url = `${url}&details=${encodeURIComponent(link.description)}`
26
- if (link.address)
27
- url = `${url}&location=${encodeURIComponent(link.address)}`
28
-
29
- return url
30
- }
31
-
32
- function convertTZ(date: Date | string, tzString: string): Date {
33
- return new Date((typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', { timeZone: tzString }))
34
- }
@@ -1,72 +0,0 @@
1
- import type { CalendarLink } from '../types'
2
- import { useDateFormat, useMax } from '@stacksjs/browser'
3
- import md5 from 'crypto-js/md5'
4
-
5
- export function generateIcs(link: CalendarLink): string {
6
- const dateFormat = 'YYYYMMDD'
7
- const timeFormat = 'YYYYMMDDThhmmss'
8
-
9
- const uid = `UID:${generateEventUid(link)}`
10
- const summary = `SUMMARY:${link.title}`
11
-
12
- const url = [
13
- 'BEGIN:VCALENDAR',
14
- 'VERSION:2.0', // @see https://datatracker.ietf.org/doc/html/rfc5545#section-3.7.4
15
- 'PRODID:Spatie calendar-links', // @see https://datatracker.ietf.org/doc/html/rfc5545#section-3.7.3
16
- 'BEGIN:VEVENT',
17
- uid,
18
- summary,
19
- ]
20
-
21
- const timezone = link.timezone || 'PST'
22
- const formatTime = `${timezone}:${timeFormat}`
23
- const dateTimeFormat = link.allDay ? dateFormat : formatTime
24
-
25
- if (link.allDay) {
26
- url.push(`DTSTAMP;TZID=${useDateFormat(link.from, dateTimeFormat).value}`)
27
- url.push(`DTSTART:${useDateFormat(link.from, dateTimeFormat).value}`)
28
- url.push(`DURATION:P${useMax(1, dateDiffInDays(link.from, link.to)).value}D`)
29
- }
30
- else {
31
- url.push(`DTSTAMP;TZID=${useDateFormat(link.from, dateTimeFormat).value}`)
32
- url.push(`DTSTART;TZID=${useDateFormat(link.from, dateTimeFormat).value}`)
33
- url.push(`DTEND;TZID=${useDateFormat(link.to, dateTimeFormat).value}`)
34
- }
35
-
36
- if (link.description)
37
- url.push(`X-ALT-DESC;FMTTYPE=text/html:${link.description}`)
38
- if (link.address)
39
- url.push(`LOCATION:${link.address}`)
40
-
41
- url.push('END:VEVENT')
42
- url.push('END:VCALENDAR')
43
-
44
- return buildLink(url)
45
- }
46
-
47
- function buildLink(propertiesAndComponents: any): string {
48
- return `data:text/calendar;charset=utf8;base64,${btoa(propertiesAndComponents.join('\r\n'))}`
49
- }
50
-
51
- // a and b are javascript Date objects
52
- function dateDiffInDays(from: Date, to: Date): number {
53
- const _MS_PER_DAY = 1000 * 60 * 60 * 24
54
-
55
- // Discard the time and time-zone information.
56
- const utc1 = Date.UTC(from.getFullYear(), from.getMonth(), from.getDate())
57
- const utc2 = Date.UTC(to.getFullYear(), to.getMonth(), to.getDate())
58
-
59
- return Math.floor((utc2 - utc1) / _MS_PER_DAY)
60
- }
61
-
62
- function generateEventUid(link: any): string {
63
- const atomicFormat = 'YYYY-MM-DDThh:mm:ss+00:00'
64
- const from = useDateFormat(link.from, atomicFormat).value
65
- const to = useDateFormat(link.to, atomicFormat).value
66
-
67
- return md5(`${from}${to}${link.title}`).toString()
68
- }
69
-
70
- // function escapeString(field: string): string {
71
- // return addcslashes(field, '\r\n,;')
72
- // }
@@ -1,38 +0,0 @@
1
- import type { CalendarLink } from '../types'
2
- import { useDateFormat } from '@stacksjs/browser'
3
-
4
- export function generateOutlook(link: CalendarLink): string {
5
- const dateFormat = 'YYYY-MM-DD'
6
- const timeFormat = 'YYYY-MM-DDThh:mm:ss'
7
- const BASE_URL = 'https://outlook.live.com/calendar/deeplink/compose?path=/calendar/action/compose&rru=addevent'
8
-
9
- // 20221020T170000Z/20221020T173000Z
10
- let url = BASE_URL
11
-
12
- const utcStartDateTime = convertTZ(link.from, 'UTC') // set timezone to UTC
13
- const utcEndDateTime = convertTZ(link.to, 'UTC') // set timezone to UTC
14
- const dateTimeFormat = link.allDay ? dateFormat : timeFormat
15
-
16
- url = link.allDay
17
- ? `${url}&startdt=${useDateFormat(utcStartDateTime, dateTimeFormat).value}`
18
- : `${url}&startdt=${useDateFormat(utcStartDateTime, dateTimeFormat).value}Z`
19
- url = link.allDay
20
- ? `${url}&enddt=${useDateFormat(utcEndDateTime, dateTimeFormat).value}`
21
- : `${url}&enddt=${useDateFormat(utcEndDateTime, dateTimeFormat).value}Z`
22
-
23
- if (link.allDay)
24
- url = `${url}&allday=true`
25
-
26
- url = `${url}&subject=${encodeURIComponent(link.title)}`
27
-
28
- if (link.description)
29
- url = `${url}&body=${encodeURIComponent(link.description)}`
30
- if (link.address)
31
- url = `${url}&location=${encodeURIComponent(link.address)}`
32
-
33
- return url
34
- }
35
-
36
- function convertTZ(date: Date | string, tzString: string): Date {
37
- return new Date((typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', { timeZone: tzString }))
38
- }
@@ -1,37 +0,0 @@
1
- import type { CalendarLink } from '../types'
2
- import { useDateFormat } from '@stacksjs/browser'
3
-
4
- export function generateYahoo(link: CalendarLink): string {
5
- const dateFormat = 'YYYYMMDD'
6
- const timeFormat = 'YYYYMMDDThhmmss'
7
- let url = 'https://calendar.yahoo.com/?v=60&view=d&type=20'
8
-
9
- const utcStartDateTime = convertTZ(link.from, 'UTC') // set timezone to UTC
10
- const utcEndDateTime = convertTZ(link.to, 'UTC') // set timezone to UTC
11
- const dateTimeFormat = link.allDay ? dateFormat : timeFormat
12
-
13
- if (link.allDay) {
14
- url = `${url}&ST=${useDateFormat(link.from, dateTimeFormat).value}`
15
- url = `${url}&DUR=allday`
16
- url = `${url}&ET=${useDateFormat(link.to, dateTimeFormat).value}`
17
- }
18
- else {
19
- url = `${url}&ST=${useDateFormat(utcStartDateTime, dateTimeFormat).value}Z`
20
- url = `${url}&ET=${useDateFormat(utcEndDateTime, dateTimeFormat).value}Z`
21
- }
22
-
23
- url = `${url}&TITLE=${encodeURIComponent(link.title)}`
24
-
25
- if (link.description)
26
- url = `${url}&DESC=${encodeURIComponent(link.description)}`
27
- if (link.address)
28
- url = `${url}&in_loc=${encodeURIComponent(link.address)}`
29
-
30
- return url
31
- }
32
-
33
- function convertTZ(date: Date | string, tzString: string): Date {
34
- return new Date((typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', { timeZone: tzString }))
35
- }
36
-
37
- export default generateYahoo
package/src/index.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { CalendarLink } from './types'
2
- import { generateGoogle } from './generators/google'
3
- import { generateIcs } from './generators/ics'
4
- import { generateOutlook } from './generators/weboutlook'
5
- import { generateYahoo } from './generators/yahoo'
6
-
7
- export function exportCalendarGoogle(link: CalendarLink): string {
8
- return generateGoogle(link)
9
- }
10
-
11
- export function exportCalendarIcs(link: CalendarLink): string {
12
- return generateIcs(link)
13
- }
14
-
15
- export function exportCalendarOutlook(link: CalendarLink): string {
16
- return generateOutlook(link)
17
- }
18
-
19
- export function exportCalendarYahoo(link: CalendarLink): string {
20
- return generateYahoo(link)
21
- }
package/src/types.ts DELETED
@@ -1,47 +0,0 @@
1
- import type { Ref } from 'vue'
2
-
3
- export interface CalendarStore {
4
- day: number
5
- month: Ref<number>
6
- year: Ref<number>
7
- currentMonthYear: Ref<string>
8
- currentMonthDayYear: Ref<string>
9
- datesOfThePastMonth: Ref<number[]>
10
- datesOfTheMonth: Ref<number[]>
11
- datesOfNextMonth: Ref<number[]>
12
- currentWeekView: Ref<number[]>
13
- currentWeekViewToday: Ref<number[]>
14
- }
15
-
16
- export interface Time {
17
- from: string
18
- to: string
19
- }
20
- export interface Events {
21
- date: string
22
- title: string
23
- description: string
24
- month: number
25
- day: number
26
- year: number
27
- time: Time
28
- }
29
-
30
- export interface WeekDates {
31
- month: number
32
- date: number
33
- }
34
-
35
- export interface TimeTableStyle {
36
- time: string
37
- gridRow: string
38
- }
39
- export interface CalendarLink {
40
- from: Date
41
- to: Date
42
- allDay: boolean
43
- address: string
44
- title: string
45
- description: string
46
- timezone: string
47
- }