@Override
        public Iterator<Long> iterator() {
          return new Iterator<Long>() {
            long curr = truncate(start);

            long next = BaseQueryGranularity.this.next(curr);

            @Override
            public boolean hasNext() {
              return curr < end;
            }

            @Override
            public Long next() {
              if (!hasNext()) {
                throw new NoSuchElementException();
              }

              long retVal = curr;

              curr = next;
              next = BaseQueryGranularity.this.next(curr);

              return retVal;
            }

            @Override
            public void remove() {
              throw new UnsupportedOperationException();
            }
          };
        }
UDFDateFloor.

Abstract class that converts a timestamp to a timestamp with a given granularity.
ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDateFloor.java