Saltar navegación

[Resuelto] Save Elapsed Time from JS Stopwatch in Custom post field

This support ticket is created hace 4 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por tobiasF-3 hace 4 años, 10 meses.

Asistido por: Waqar.

Autor
Mensajes
#1519765

I would like to create a tool where I start a stopwatch on a page and let it run for several hours. From
Time to time I hit the lapse-button and capture the elapsed time.

Whenever I hit the lapse button, I would like to save that elapsed time In a cred form where I add some other info and save it all together in a custom post type. Then I would get redirected back to the still running stopwatch. When I hit the lapse button again, the next custom post type with elapsed time and aome additional info that the I enter at that point) (in a cred from?) is saved. This results in the end in a list of custom post types with log time and additional info.

Herr‘s an example of a js stopwatch that I would like to capture the elapsed time info from:
enlace oculto

Is something like this possible? Orndo you have a better approach? And could you please guide me in the right directiion?

Thanks a lot
Tobias

#1520651

Hi Tobias,

Thanks for asking! I'd be happy to help.

Based on what you've shared your requirement can be split into multiple functional parts.

1. Structure of the data:

- For storing each record, you can create a new custom post type, for example, "Record".

This new post type will need three date/time type custom fields:

a). Start time: This field can have only one instance and will store the start time of an individual record post.
b). Lap time: This field can have multiple instances, to store each lap's starting time.
c). End time: This field can have only one instance and will store the end time of an individual record post.

2. User input:

- You can use a new post form to add a new record post and save it's starting time.

After that, you can use a post edit form to keep adding lap entries and then finally the end time.

Tip: You can automatically populate these fields with the current date & time, using a custom function, as suggested here:
https://toolset.com/forums/topic/auto-fill-timestamp-to-cred-form-field/#post-1070073

3. Dynamic display:

- Once you have the data structure and input part sorted out, the last step would be to show dynamic elements like stop-watch based on the calculations of that available data. For this, you'll need a fair deal of customizations and familiarity with custom PHP and scripts.

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1521631

Hey Waqar. Thanks for this great guide.

About point 2: how can In alter this basic functionality to not store the current date and time, but to start the clock at 0 seconds and stop the clovk at say 2:01:05 hours and store this info in the start, lapse and end fields of the form?

And about poinr 3: I think I was not explaining this clearly enough: I am looking for a way to use the JS stopwatch to create entries for the start, lapse and end fields, not to dusplay the saved results from fields. So basically the reverse functionality 🙂

Thx for looking into this
T

#1528445

Hi Tobias,

Thank you for waiting.

Point 2:
If I understand your requirements correctly, saving the date and time of the individual event ( like start, stop and each lap's beginning ) will let you calculate the difference between them to get the required intervals.

For example, suppose you have this data:

Start time: 26 FEB, 2020, 2:00 pm
Lap time: 26 FEB, 2020, 3:30 pm
Lap time: 26 FEB, 2020, 4:15 pm
Lap time: 26 FEB, 2020, 5:00 pm
End time: 26 FEB, 2020, 6:20 pm

From the above data, we can calculate or draw the following conclusions:

1. The record's total running time was 4 hours and 20 mins.
2. There were a total of 4 laps.
3. Lap 1 lasted for 1 hour and 30 mins.
4. Lap 2 lasted for 45 mins.
5. Lap 3 lasted for 45 mins.
6. Lap 4 lasted for 1 hour and 20 mins.

To the best of my knowledge, WordPress, PHP, and jQuery doesn't offer running any virtual instances of clocks, and the point of reference for such calculations would always be current date & time stamp.

Point 3:

As I mentioned in my previous reply, manipulation of dynamic data entry and display with respect to a stopwatch would require fair deal of customization. Since this is something that is beyond the scope of support that we can provide over the forum, you can discuss this requirement in more detail with one of our recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1534619

Thx Waqar, it looks like this is more complex that I've hoped. I will try to contact a contractor to look further into this.