Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(557)

Unified Diff: pkg/present/parse.go

Issue 6868048: code review 6868048: go.talks/pkg/present: add Time field to Document (Closed)
Patch Set: diff -r 1b63239d44e9 https://code.google.com/p/go.talks Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/present/doc.go ('k') | present/templates/slides.tmpl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/present/parse.go
===================================================================
--- a/pkg/present/parse.go
+++ b/pkg/present/parse.go
@@ -14,6 +14,7 @@
"log"
"net/url"
"strings"
+ "time"
"unicode"
"unicode/utf8"
)
@@ -48,6 +49,7 @@
type Doc struct {
Title string
Subtitle string
+ Time time.Time
Authors []Author
Sections []Section
Template *template.Template
@@ -217,6 +219,13 @@
if !ok {
return nil, errors.New("no subtitle")
}
+ text, ok := lines.next()
+ if !ok {
+ return nil, errors.New("unexpected EOF")
+ }
+ if t, ok := parseTime(text); ok {
+ doc.Time = t
+ }
if mode&TitlesOnly > 0 {
return doc, nil
}
@@ -411,3 +420,17 @@
}
return Link{URL: u}
}
+
+func parseTime(text string) (t time.Time, ok bool) {
+ t, err := time.Parse("15:04 2 Jan 2006", text)
+ if err == nil {
+ return t, true
+ }
+ t, err = time.Parse("2 Jan 2006", text)
+ if err == nil {
+ // at 11am UTC it is the same date everywhere
+ t = t.Add(time.Hour * 11)
+ return t, true
+ }
+ return time.Time{}, false
+}
« no previous file with comments | « pkg/present/doc.go ('k') | present/templates/slides.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b