Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: apognu/gocal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.0
Choose a base ref
...
head repository: apognu/gocal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.9.1
Choose a head ref
  • 14 commits
  • 10 files changed
  • 7 contributors

Commits on Jul 1, 2021

  1. Copy the full SHA
    7366fd3 View commit details
  2. rrule: fix COUNT + BYDAY case

    essentially the count value would get decreased by more then 1 during the BYDAY
    rule expansion without checking for underruns.
    julixau authored and apognu committed Jul 1, 2021
    Copy the full SHA
    b0a13d1 View commit details

Commits on Nov 14, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    apognu Antoine POPINEAU
    Copy the full SHA
    94524ad View commit details

Commits on Mar 28, 2022

  1. Copy the full SHA
    6e779b6 View commit details
  2. Updated log level

    danesparza authored and apognu committed Mar 28, 2022
    Copy the full SHA
    73154ea View commit details
  3. Changed debugging output

    danesparza authored and apognu committed Mar 28, 2022
    Copy the full SHA
    6561edd View commit details
  4. Added reference links. Cleaned up rrule test. Added additional test f…

    …or multiple exdates
    danesparza authored and apognu committed Mar 28, 2022
    Copy the full SHA
    1cd5d1b View commit details
  5. Cleaned up go mod stuff

    danesparza authored and apognu committed Mar 28, 2022
    Copy the full SHA
    fc4ccf1 View commit details

Commits on May 30, 2023

  1. Add support for quoted property parameters

    This CL adds support for quoted property parameters (RFC5545, 3.1.1), specifically the following beauties that Office365 likes to spout out:
    
    ```
    DTSTART;TZID="tzone://Microsoft/Utc":20230102T160000
    ```
    
    This change adds a naive split implementation that respects said quoted parameters, which is only used in case quotes occur on the left-hand before the separating colon. The performance impact depends on the line-size of the properties in the ICS document. Benchmark measures about about 4ns for 20 char long lines, about 5ns for 100 char long lines.
    
    ```
    $ go test -bench=.
    goos: darwin
    goarch: arm64
    pkg: github.com/apognu/gocal
    Benchmark_splitLineTokens20-8    	35675428	        33.41 ns/op
    Benchmark_stringSplitN20-8       	40056913	        29.56 ns/op
    Benchmark_splitLineTokens100-8   	34151101	        34.99 ns/op
    Benchmark_stringSplitN100-8      	39473630	        29.93 ns/op
    PASS
    ok  	github.com/apognu/gocal	5.900s
    ```
    ukautz authored and apognu committed May 30, 2023
    Copy the full SHA
    9fe792c View commit details
  2. add CLASS support

    bakerag1 authored and apognu committed May 30, 2023
    Copy the full SHA
    b7000c8 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    apognu Antoine POPINEAU
    Copy the full SHA
    147e7b3 View commit details
  4. 1

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    apognu Antoine POPINEAU
    Copy the full SHA
    31d5c7a View commit details

Commits on Oct 24, 2024

  1. fix: check recurring event with correct timezone

    using local timezone leads to error in data comparison
    alexsmshchnko authored and apognu committed Oct 24, 2024
    Copy the full SHA
    bb14ecd View commit details
  2. test: scenario with recurrence TZID

    Aleksandr Semashchenko authored and apognu committed Oct 24, 2024
    Copy the full SHA
    c1eae90 View commit details
Showing with 595 additions and 131 deletions.
  1. +8 −0 README.md
  2. +91 −0 attrs.go
  3. +2 −2 go.mod
  4. +2 −2 go.sum
  5. +108 −88 gocal.go
  6. +315 −15 gocal_test.go
  7. +8 −4 parser/time.go
  8. +24 −9 parser/time_test.go
  9. +2 −2 rrule.go
  10. +35 −9 types.go
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -71,6 +71,14 @@ By default, any error in parsing an event will result in the whole feed being ab
* `StrictModeFailEvent` - skip the current event
* `StrictModeFailAttribute` - skip parsing of the failing attribute, set the `Valid` attribute of the event to `false`

### Duplicate attribute behavior

The behavior when an attribute is duplicated can be customized with the `Duplicate.Mode` field. The default is to follow the configured strict mode behavior, but you can relax those rule by instructing `Gocal` to keep either the first or last value.

* `DuplicateModeFailStrict`
* `DuplicateModeKeepFirst`
* `DuplicateModeKeepLast`

## Limitations

I do not pretend this abides by [RFC 5545](https://tools.ietf.org/html/rfc5545), this only covers parts I needed to be parsed for my own personal use. Among other, most property parameters are not handled by the library, and, for now, only the following properties are parsed:
91 changes: 91 additions & 0 deletions attrs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package gocal

import (
"fmt"
"time"

"github.com/apognu/gocal/parser"
)

// resolve() processes a line's value, taking duplicate rule into account to inform failure modes.
// It takes as parameters:
// - A Gocal and Line instance
// - A pointer to the resulting field in the in-process event
// - A resolver function that parse the raw string value into the desired output type
// - An optional post-processing function that can modify other event attributs, if necessary
func resolve[T comparable](gc *Gocal, l *Line, dst *T, resolve func(gc *Gocal, l *Line) (T, T, error), post func(gc *Gocal, out T)) error {
// Retrieve the parsed value for the field, as well as its default value
value, empty, err := resolve(gc, l)

if err != nil {
return err
}

// Apply duplicate attribute rule if the target attribute is not empty (note: would fail for empty string values)
if dst != nil && *dst != empty {
if gc.Duplicate.Mode == DuplicateModeFailStrict {
return NewDuplicateAttribute(l.Key, l.Value)
}
}

// If the value is empty or the duplicate mode allows further processing, set the value
if *dst == empty || gc.Duplicate.Mode == DuplicateModeKeepLast {
*dst = value

if post != nil && dst != nil {
post(gc, *dst)
}
}

return nil
}

func resolveString(gc *Gocal, l *Line) (string, string, error) {
return l.Value, "", nil
}

func resolveDate(gc *Gocal, l *Line) (*time.Time, *time.Time, error) {
d, err := parser.ParseTime(l.Value, l.Params, parser.TimeStart, false, gc.AllDayEventsTZ)
if err != nil {
return nil, nil, fmt.Errorf("could not parse: %s", err)
}

return d, nil, nil
}

func resolveDateEnd(gc *Gocal, l *Line) (*time.Time, *time.Time, error) {
d, err := parser.ParseTime(l.Value, l.Params, parser.TimeEnd, false, gc.AllDayEventsTZ)
if err != nil {
return nil, nil, fmt.Errorf("could not parse: %s", err)
}

return d, nil, nil
}

func resolveDuration(gc *Gocal, l *Line) (*time.Duration, *time.Duration, error) {
d, err := parser.ParseDuration(l.Value)
if err != nil {
return nil, nil, fmt.Errorf("could not parse: %s", err)
}

return d, nil, nil
}

func resolveOrganizer(gc *Gocal, l *Line) (*Organizer, *Organizer, error) {
o := Organizer{
Cn: l.Params["CN"],
DirectoryDn: l.Params["DIR"],
Value: l.Value,
}

return &o, nil, nil
}

func resolveGeo(gc *Gocal, l *Line) (*Geo, *Geo, error) {
lat, long, err := parser.ParseGeo(l.Value)
if err != nil {
return nil, nil, err
}

return &Geo{lat, long}, nil, nil
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/apognu/gocal

go 1.13
go 1.21

require (
github.com/ChannelMeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61
github.com/channelmeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.0
github.com/stretchr/testify v1.2.2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -6,5 +6,5 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.0 h1:LThGCOvhuJic9Gyd1VBCkhyUXmO8vKaBFvBsJ2k03rg=
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Loading