utils.ts 701 B

1234567891011121314151617181920212223242526
  1. export function generateNewTaskId(): string {
  2. /**
  3. * Generate a new task id based on the current timestamp and a random number.
  4. */
  5. return `${Date.now()}-${Math.floor(Math.random() * (999999 - 100000 + 1) + 100000)}`;
  6. }
  7. export function getCurrentTimestampStr(): string {
  8. /**
  9. * Get the current timestamp as a string in the format yyyy-MM-dd HH:mm:ss
  10. * using local timezone.
  11. *
  12. * @returns Formatted datetime string in local time
  13. */
  14. return new Date()
  15. .toLocaleString('en-US', {
  16. year: 'numeric',
  17. month: '2-digit',
  18. day: '2-digit',
  19. hour: '2-digit',
  20. minute: '2-digit',
  21. second: '2-digit',
  22. hour12: false,
  23. })
  24. .replace(',', '');
  25. }