mardi 14 juillet 2020

Check two timestamps are not in range of some coupled timestamps

In a laravel project I want to store a new data and while checking some of attributes it is needed to check the starting and ending time(which are timestamps) doesn't overlap other database collections time range.

for example: there are 3 collections which have a start_time and an end_time as timestamps and for each one of them I want to check the new data is not between any of these ranges.

The data I need to validate is like:

{
    "start" : "2020-07-11T10:30:00Z",
    "end" : "2020-07-14T11:30:00Z"
}

the input datetime format naturally will be converted to timestamps before checking!

and the data called from database looks like below:

[
    {
        "start_time": 1594425600,
        "end_time": 1594684800,
    },
    {
        "start_time": 1594771200,
        "end_time": 1595030400,
    },
    {
        "start_time": 1595073600,
        "end_time": 1595419200,
    }
]

and the point is to check is the inserted data does not overlap the range between any of coupled start and end timestamps.

I'm using laravel 5.7 and the database is mongoDB also using Moloquent(similar to Eloquent ORM)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire