Question: i want to some time calculation with this code:

```
$timestamp = mt_rand(1, 2147385600);
$oldDate = date("Y-m-d H:i:s", $timestamp);
$date = date("Y-m-d H:i:s", strtotime("-6 hour", (floor(strtotime($oldDate) / 6 / 60 / 60) * 6 * 60 * 60)));
echo $oldDate . " - " . $date;

```

i want to calculate exact previous time period (6 hours) of given time not included itself. for example: 

```
2001-10-23 07:56:28 -> 2001-10-23 00:00:00 to 2001-10-23 05:59:59
2037-01-31 01:31:25 -> 2037-01-30 18:00:00 to 2037-01-30 23:59:59

```

this code working very well. but when i added `date_default_timezone_set`, result becomes wrong.

how does `date_default_timezone_set` break the calculations? how can i solve this?

i added a link with working and non working sample. pleasse check this out:
<http://phpfiddle.org/lite/code/32ug-7w4y> please click `run-f9` a few times.

Answer: 
I had a similar problem and solved it by generating a new datasource every time the data changes and then set the paginator and sorter.

**EDIT:** Add setter for paginator and sorter and change `static` attribute to false. Also add a check before setting the paginator and sorter in the `setDataSource` function.

```
@ViewChild(MatPaginator, {static: false}) paginator: MatPaginator; // change static to false here
@ViewChild(MatPaginator, {static: false}) set matPaginator(value: MatPaginator) {
  if(this.dataSource && value) {
    this.dataSource.paginator = value;
  }
}

@ViewChild(MatSort, {static: false}) sort: MatSort; // change static to false here
@ViewChild(MatSort, {static: false}) set matSort(value: MatSort) {
  if(this.dataSource && value) {
    this.dataSource.sort = value;
  }
}

public setDataSource(data,columns) {  // data -> array of elements; columns -> columns you wish to display
  this.displayedColumns = columns;        
  this.dataSource = new MatTableDataSource<any>(data);  // replace any with your data type
  if(this.paginator) {   // add check here
    this.dataSource.paginator = this.paginator;
  }
  if(this.sort) {  // add check here
    this.dataSource.sort = this.sort;
  }
}

```
In case the complete data is loaded into the client, you should use `MatTableDataSource`. This class is aimed to be used for filtering, sorting and pagination of a client-side data array. 

When filtering, sorting and pagination are done server-side, the use of this class is not appropriate. In such cases, the relevant data may be kept in a simple array, hence no need to implement a specific interface. A good example is given at <https://blog.angular-university.io/angular-material-data-table/>.