Skip to content

Commit

Permalink
Grumble: debugging pretty time (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Jun 25, 2024
1 parent 875d974 commit d3fc1b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libreforms_fastapi/app/static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@ function renderUserRelationships(users) {


function prettifyTimeDiff(dateTimeStr) {
console.log(dateTimeStr);

// Parse the date string into a Date object
const date = new Date(dateTimeStr);
console.log(date);

// Get the current date and time
const now = new Date();
console.log(now);

// Calculate the difference in seconds
const timeDiff = (now - date) / 1000; // convert milliseconds to seconds
console.log(timeDiff);

if (timeDiff < 3600) {
if (timeDiff / 30 < 1) {
Expand Down
2 changes: 2 additions & 0 deletions libreforms_fastapi/utils/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,11 @@ def get_form_html(

if placeholder:
field_html += f'<option value="">{placeholder}</option>'

for option in field_info['options']:
selected = "selected" if default and (option == default or option in default) else ""
field_html += f'<option value="{option}" {selected}>{option}</option>'

field_html += '''
</select>'''
if isinstance(links_to_form, str):
Expand Down

0 comments on commit d3fc1b8

Please sign in to comment.