Question: I am building a simple web app with ReactJS frontend and Laravel backend using REST API.   

Here are my codes.

**Laravel Backend API for authentication**

```php
class UserController extends Controller 
{
    public function authenticate(Request $request) 
    {
        $credentials = $request->only('email', 'password');

        error_log(print_r($credentials, TRUE));

        try {
            if (! $token = JWTAuth::attempt($credentials)) {
                return response()->json(['error' => 'invalid_credentials'], 400);
            }
        } catch (JWTException $e) {
            return response()->json(['error' => 'could_not_create_token'], 500);
        }

        return  response()->json(compact('token'));
    }
}

```

**ReactJS Frontend**

```js
login() {
    fetch ('http://localhost:8000/api/login',
        {
            header: {
                "Accept": "application/json, text/plain, */*",
                "Content-Type": "application/json",
            },
            method: "POST",
            body: JSON.stringify({email: this.state.email, password: this.state.password}),
        }
    )
    .then(response => console.log(response));
}

```

And the problem is, if you send the fetch request in react, the php terminal shows nothing but an empty array and receive:

> 
> 400 Bad Request with invalid\_credentials response 
> 
> 
> 

while Postman request is showing exactly what I gonna see.

What's the problem? Is my backend wrong?

Answer: 
In my approach i use [astropy](https://www.astropy.org/) library for converting gps time into date time format. Next convert this time to [Datetimeindex](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.html) with pandas;

=^..^=

```
import pandas as pd
import pvlib as pvl
from astropy.time import Time

latitude = -23.048576 # degress
longitude = -46.305043 # degrees

# convert gps seconds to time format
gps_time = 138088.886582
t = Time(gps_time, format='gps')
t = Time(t, format='iso')

# create empty df
df = pd.DataFrame(columns = ['Timestamp'])

# create date time series
time_series = pd.to_datetime(str(t), infer_datetime_format=True)

# append time series to data frame
df = df.append({'Timestamp': pd.to_datetime(time_series)}, ignore_index=True)
df = df.append({'Timestamp': pd.to_datetime(time_series)}, ignore_index=True)

# create time index
time_index = pd.DatetimeIndex(df.Timestamp)

# calculate hour angle
hour_angle = pvl.solarposition.hour_angle(time_index, longitude, latitude*60)

```

Output:

```
[-356.58415383 -356.58415383]

```
Instead of using `datetime` or strings to fill your `DatetimeIndex`, create `pandas.Timestamp`, the `pandas` version of `datetime.datetime`.

First build a Posix timestamp, aka seconds from epoch:

```
week_number = 2024
t_gps = 138088.886582
leapsecond = 37
posix_ts = week_number * 7 * 24 * 60 * 60 + t_gps + leapsecond

```

Then build a `Timestamp`:

```
pandas_ts = Timestamp.utcfromtimestamp(posix_ts)
>>> Timestamp('2008-10-17 14:22:05.886582')

```

At this point, the `Timestamp` is "naive": while build as UTC, it does not contain time zone information, so:

```
pandas_ts = pandas_ts.tz_localize("UTC")
>>> Timestamp('2008-10-17 14:22:05.886582+0000', tz='UTC')

```

Finally, you can convert to your local time zone:

```
pandas_ts = pandas_ts.tz_convert("my_time_zone")  # replace by correct tz
>>> Timestamp('2008-10-17 NN:22:05.886582+XXXX', tz='my_time_zone')

```

and build the required `DatetimeIndex`:

```
di = DatetimeIndex([pandas_ts])
print(di)  # shows the time zone in the type (dtype='datetime64[ns, my_time_zone]')

long = -46.305043
eq_time = pvl.solarposition.equation_of_time_pvcdrom(295)
hour_angle = pvl.solarposition.hour_angle(di, long, eq_time)
print(hour_angle)

```

Don't mix `tz_localize` and `tz_convert` and remember to always set the timezone. This way you control the creation of the `DatetimeIndex`, using string you rely on the automatic parsing by `pandas`, problematic with time zone.