altmp / altv-issues

Issues and roadmap for alt:V project
93 stars 16 forks source link

(Javascript) Make sure dates are sent correctly (in emit) #1118

Closed ppaglier closed 3 years ago

ppaglier commented 3 years ago

Suggestion

In Javascript, when you send a date (class Date), you should receive a date (class Date), because actually when you send a Date, you recieve an empty Object

Use cases

Sending date in emit/emitClient/emitServer whithout format the date to timestamp or ISO

Describe the solution you'd like

When you send a Date, you should recieve a date (class Date) or formated date (ISO or timestamp)

Describe alternatives you've considered

The only way i found for doing this without any update is to format the date to ISO or timestamp before sending data, then create Date by the ISO or timestamp

Additional context

const emitDate = new Date();
    console.log(emitDate);
    alt.on('test', (date) => {
        console.log(date);
    });
    alt.emit('test', emitDate);

and the current result is :

2021-09-16T19:00:06.104Z
{}

but it should be this

2021-09-16T19:00:06.104Z
2021-09-16T19:00:06.104Z
FabianTerhorst commented 3 years ago

You should emit it via a timestamp as e.g. Long.

LeonMrBonnie commented 3 years ago

You can simply send the date as JSON with toJSON or as a ISO string, as a timestamp etc. Also it would probably make problems across different time zones. Dates aren't a commonly used data structure so there isn't really a need to add them as a MValue.

ppaglier commented 3 years ago

You should emit it via a timestamp as e.g. Long.

You can simply send the date as JSON with toJSON or as a ISO string, as a timestamp etc. Also it would probably make problems across different time zones. Dates aren't a commonly used data structure so there isn't really a need to add them as a MValue.

Yes, but if a send an array or multiples values wich contains dates (like an array of object which contains maybe an other array of object that contains a Date), i need to make a loop or format all dates before sending them, then after i recieved them, i need to recreate Date manually to use it as a Date

FabianTerhorst commented 3 years ago

I dont think we can add a own mvalue for each possible Platform Type.

martonp96 commented 3 years ago

You cannot expect other modules to add support for nonexistent types, e.g javascript Date, please use timestamp.