Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enhanced func timestampToRelativeTime #508

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

uykukacinca
Copy link

@uykukacinca uykukacinca commented Mar 24, 2025

Updated functions are more configurable and feature-rich while maintaining the same core functionality. It allows for more precise time displays and better customization options through data attributes.

Major Changes

Time Unit Definition:
Consolidated array TIME_UNITS with tuples of [label, seconds]

Enhanced function timestampToRelativeTime:

  • Added support for multiple units via units parameter
  • Added relative parameter to toggle "ago"/"in" text
  • More flexible output format combining multiple units
  • Added validation for invalid timestamps

Updated function updateRelativeTimeForElements:

  • Added support for custom units via data-units attribute
  • Added relative time display via data-show-relative attribute
  • Performance optimization: only updates if content changed

Update Interval:
Old: 60 seconds (60 * 1000)
New: 1 seconds (1 * 1000)

Examples

<span data-dynamic-relative-time="1764472280">
  8mo
<span data-dynamic-relative-time="1764472280" data-show-relative="true">
  in 8mo
<span data-dynamic-relative-time="1764472280" data-units="2" data-show-relative="true">
  in 8mo 10d
<span data-dynamic-relative-time="1805893973" data-units="6" data-show-relative="true">
  in 1y 12mo 4d 22h 25m 29s

<span data-dynamic-relative-time="1719273224">
  9mo
<span data-dynamic-relative-time="1719273224" data-show-relative="true">
  9mo ago
<span data-dynamic-relative-time="1719273224" data-units="2" data-show-relative="true">
  9mo 2d ago
<span data-dynamic-relative-time="1679663573" data-units="6" data-show-relative="true">
  2y 1d 1h 34m 31s ago

@uykukacinca uykukacinca deleted the patch-1 branch March 24, 2025 13:55
@uykukacinca uykukacinca restored the patch-1 branch March 24, 2025 13:56
@uykukacinca uykukacinca reopened this Mar 24, 2025
@uykukacinca uykukacinca changed the title enhanced func timestampToRelativeTime refactor: enhanced func timestampToRelativeTime Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant