Skip to content

Commit

Permalink
extract time from event summary and correct the order in the event vi…
Browse files Browse the repository at this point in the history
…ew (close #132)
  • Loading branch information
itchyny committed Dec 14, 2017
1 parent 6d6be26 commit 25009a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions autoload/calendar/event/local.vim
Expand Up @@ -2,7 +2,7 @@
" Filename: autoload/calendar/event/local.vim
" Author: itchyny
" License: MIT License
" Last Change: 2017/07/02 08:22:50.
" Last Change: 2017/12/14 20:36:19.
" =============================================================================

let s:save_cpo = &cpo
Expand Down Expand Up @@ -64,7 +64,8 @@ function! s:self.get_events_one_month(year, month, ...) dict abort
\ , 'endtime': endtime
\ , 'ymdnum': (((ymd[0] * 100 + ymd[1]) * 100) + ymd[2])
\ , 'hms': ymd[3:]
\ , 'sec': ((ymd[3] * 60) + ymd[4]) * 60 + ymd[5]
\ , 'sec': isTimeEvent ? ((ymd[3] * 60) + ymd[4]) * 60 + ymd[5]
\ : itm.summary =~# '\v^\d\d?:\d\d(:\d\d)?\s+' ? s:extract_time_sec(itm.summary) : 0
\ , 'ymd': ymd[:2]
\ , 'endhms': endymd[3:]
\ , 'endymd': endymd[:2] }))
Expand All @@ -73,6 +74,11 @@ function! s:self.get_events_one_month(year, month, ...) dict abort
return events
endfunction

function! s:extract_time_sec(summary) abort
let xs = matchlist(a:summary, '\v^(\d\d?):(\d\d)%(:(\d\d))?')
return ((xs[1] * 60) + xs[2]) * 60 + xs[3]
endfunction

function! s:self.update(calendarId, eventId, title, year, month, ...) dict abort
let calendarList = self.calendarList()
let [y, m] = [printf('%04d', a:year), printf('%02d', a:month)]
Expand Down
10 changes: 8 additions & 2 deletions autoload/calendar/google/calendar.vim
Expand Up @@ -2,7 +2,7 @@
" Filename: autoload/calendar/google/calendar.vim
" Author: itchyny
" License: MIT License
" Last Change: 2017/05/23 22:00:43.
" Last Change: 2017/12/14 20:34:29.
" =============================================================================

let s:save_cpo = &cpo
Expand Down Expand Up @@ -213,7 +213,8 @@ function! calendar#google#calendar#getEvents(year, month, ...) abort
\ , 'endtime': endtime
\ , 'ymdnum': (((ymd[0] * 100 + ymd[1]) * 100) + ymd[2])
\ , 'hms': ymd[3:]
\ , 'sec': ((ymd[3] * 60) + ymd[4]) * 60 + ymd[5]
\ , 'sec': isTimeEvent ? ((ymd[3] * 60) + ymd[4]) * 60 + ymd[5]
\ : itm.summary =~# '\v^\d\d?:\d\d(:\d\d)?\s+' ? s:extract_time_sec(itm.summary) : 0
\ , 'ymd': ymd[:2]
\ , 'endhms': endymd[3:]
\ , 'endymd': endymd[:2] }))
Expand Down Expand Up @@ -244,6 +245,11 @@ function! calendar#google#calendar#getEvents(year, month, ...) abort
return events
endfunction

function! s:extract_time_sec(summary) abort
let xs = matchlist(a:summary, '\v^(\d\d?):(\d\d)%(:(\d\d))?')
return ((xs[1] * 60) + xs[2]) * 60 + xs[3]
endfunction

function! calendar#google#calendar#sorter(x, y) abort
return a:x.calendarId ==# a:y.calendarId
\ ? (a:x.sec == a:y.sec
Expand Down

0 comments on commit 25009a8

Please sign in to comment.