Пример #1
0
func TestFromString(t *testing.T) {
	t.Parallel()

	// test with bad format
	_, err := duration.FromString("asdf")
	assert.Equal(t, err, duration.ErrBadFormat)

	// test with month
	_, err = duration.FromString("P1M")
	assert.Equal(t, err, duration.ErrNoMonth)

	// test with good full string
	dur, err := duration.FromString("P1Y2DT3H4M5S")
	assert.Nil(t, err)
	assert.Equal(t, 1, dur.Years)
	assert.Equal(t, 2, dur.Days)
	assert.Equal(t, 3, dur.Hours)
	assert.Equal(t, 4, dur.Minutes)
	assert.Equal(t, 5, dur.Seconds)

	// test with good week string
	dur, err = duration.FromString("P1W")
	assert.Nil(t, err)
	assert.Equal(t, 1, dur.Weeks)
}
Пример #2
0
				if c.Args().Present() {
					task, err = coord.Get(c.Args().First())
				} else {
					task, err = coord.NextSelected()
				}
				if err != nil {
					fmt.Fprintf(os.Stderr, "Error getting next task: %s\n", err.Error())
					return
				}

				fmt.Fprintf(os.Stdout, "Delaying: %s\n", task)

				// parse until
				until := time.Now()
				if c.String("until") != "" {
					dur, err := duration.FromString(c.String("until"))
					if err != nil {
						fmt.Fprintf(os.Stderr, "Error parsing until: %s\n", err.Error())
						return
					}

					until = until.Add(dur.ToDuration())
				}

				err = coord.Delay(task.ID, until)
				if err != nil {
					fmt.Fprintf(os.Stderr, "Error delaying %s: %s\n", task.ID, err.Error())
					return
				}

				err = coord.Close()