Testing Complex Temporal Relationships Involving Multiple Granularities and Its Application to Data Mining