Browse Source

Add IsTime method to Cell.

G. Rossin 7 years ago
parent
commit
2952a2425b
2 changed files with 19 additions and 0 deletions
  1. 6 0
      cell.go
  2. 13 0
      cell_test.go

+ 6 - 0
cell.go

@@ -100,6 +100,12 @@ func (c *Cell) SetFloat(n float64) {
 	c.SetValue(n)
 	c.SetValue(n)
 }
 }
 
 
+// IsTime returns true if the cell stores a time value.
+func (c *Cell) IsTime() bool {
+	c.getNumberFormat()
+	return c.parsedNumFmt.isTimeFormat
+}
+
 //GetTime returns the value of a Cell as a time.Time
 //GetTime returns the value of a Cell as a time.Time
 func (c *Cell) GetTime(date1904 bool) (t time.Time, err error) {
 func (c *Cell) GetTime(date1904 bool) (t time.Time, err error) {
 	f, err := c.Float()
 	f, err := c.Float()

+ 13 - 0
cell_test.go

@@ -329,6 +329,19 @@ func (l *CellSuite) TestCellTypeFormatHandling(c *C) {
 		c.Assert(val, Equals, testCase.formattedValueOutput)
 		c.Assert(val, Equals, testCase.formattedValueOutput)
 	}
 	}
 }
 }
+
+func (s *CellSuite) TestIsTime(c *C) {
+	cell := Cell{}
+	isTime := cell.IsTime()
+	c.Assert(isTime, Equals, false)
+	cell.Value = "43221"
+	c.Assert(isTime, Equals, false)
+	cell.NumFmt = "d-mmm-yy"
+	cell.Value = "43221"
+	isTime = cell.IsTime()
+	c.Assert(isTime, Equals, true)
+}
+
 func (s *CellSuite) TestGetTime(c *C) {
 func (s *CellSuite) TestGetTime(c *C) {
 	cell := Cell{}
 	cell := Cell{}
 	cell.SetFloat(0)
 	cell.SetFloat(0)