Skip to content

Commit

Permalink
Add documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
leekchan committed Aug 2, 2015
1 parent 756bf5f commit e77b21d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions strftime.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func weekNumber(t *time.Time, char int) int {
return (t.YearDay() + 6 - weekday) / 7
}

// Strftime formats time.Date according to the directives in the given format string. The directives begins with a percent (%) character.
func Strftime(t *time.Time, format string) string {
var result string

Expand Down
7 changes: 7 additions & 0 deletions timedelta.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ func abs(v time.Duration) time.Duration {
return v
}

// Timedelta represents a duration between two dates.
// All fields are optional and default to 0. You can initialize any type of timedelta by specifying field values which you want to use.
type Timedelta struct {
days, seconds, microseconds, milliseconds, minutes, hours, weeks time.Duration
}

// Add returns the Timedelta t+t2.
func (t *Timedelta) Add(t2 *Timedelta) Timedelta {
return Timedelta{
days: t.days + t2.days,
Expand All @@ -27,6 +30,7 @@ func (t *Timedelta) Add(t2 *Timedelta) Timedelta {
}
}

// Subtract returns the Timedelta t-t2.
func (t *Timedelta) Subtract(t2 *Timedelta) Timedelta {
return Timedelta{
days: t.days - t2.days,
Expand All @@ -39,6 +43,7 @@ func (t *Timedelta) Subtract(t2 *Timedelta) Timedelta {
}
}

// Abs returns the absolute value of t
func (t *Timedelta) Abs() Timedelta {
return Timedelta{
days: abs(t.days),
Expand All @@ -51,6 +56,7 @@ func (t *Timedelta) Abs() Timedelta {
}
}

// Duration() returns time.Duration. time.Duration can be added to time.Date.
func (t *Timedelta) Duration() time.Duration {
return t.days*24*time.Hour +
t.seconds*time.Second +
Expand All @@ -61,6 +67,7 @@ func (t *Timedelta) Duration() time.Duration {
t.weeks*7*24*time.Hour
}

// String returns a string representing the Timedelta's duration in the form "72h3m0.5s".
func (t *Timedelta) String() string {
return t.Duration().String()
}

0 comments on commit e77b21d

Please sign in to comment.