Ejemplo n.º 1
0
func loadDate(value string) time.Time {
	date, extra, err := transaction.ParseDate(value)
	if err != nil {
		fatalErr(err)
	}

	if len(extra) > 0 {
		fatalErr(fmt.Errorf("Invalid date %s", value))
	}

	return date
}
Ejemplo n.º 2
0
package transaction_test

import (
	"github.com/apoydence/ledger/transaction"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Date", func() {
	Describe("DateToString()", func() {
		It("outputs a string that is the same as the parsed", func() {
			line := "2015/10/31"
			date, _, _ := transaction.ParseDate(line)
			Expect(transaction.DateToString(date)).To(Equal(line))
		})
	})

	Describe("Parse", func() {
		Context("with nothing after the date", func() {
			It("returns the Date and an empty remaning", func() {
				line := "2015/10/12"
				date, remaining, err := transaction.ParseDate(line)

				Expect(err).ToNot(HaveOccurred())
				Expect(remaining).To(BeEmpty())
				Expect(date.Year()).To(Equal(2015))
				Expect(date.Month()).To(BeEquivalentTo(10))
				Expect(date.Day()).To(Equal(12))
			})

			It("returns the Date with a single month digit", func() {