@feelinglovelynow/datetime-local
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

🕉 @feelinglovelynow/datetime-local

💎 Install

pnpm add @feelinglovelynow/datetime-local

🤓 Unit Tests

Statements

🙏 Description

  • First function accepts a Date object and returns a string that may be used as a value in an input that has a type of datetime-local - YYYY-MM-DDTHH:mm
  • Second function accepts a datetime-local input's value and returns a date time string format based on ISO 8601 - YYYY-MM-DDTHH:mm:ss.sssZ

💚 toInputValue()

import { toInputValue } from '@feelinglovelynow/datetime-local'

const date = new Date((new Date()).getTime() + (3 * 60000)) // now + 3 minutes
const value = toInputValue(date)
<input bind:value={ value } type="datetime-local">
  • 🔥 Errors we may throw
if (!(date instanceof Date) || date.toString() === 'Invalid Date') throw { id: 'fln__datetime-local__invalid-date', message: 'Please pass toInputValue() a valid Date object', _errorData: { date } }

💛 toISOString()

  • Accepts a datetime-local input's value and returns a date time string format based on ISO 8601 - YYYY-MM-DDTHH:mm:ss.sssZ
  • toISOString(date: string): string
  • Example:
import { toInputValue, toISOString } from '@feelinglovelynow/datetime-local'

const date = new Date()
date.setDate(date.getDate() - 7) // now - 7 days
const iso = toISOString(toInputValue(date)) // ready for db insert
  • 🔥 Errors we may throw
if (!date || typeof date !== 'string') throw { id: 'fln__datetime-local__empty-date', message: 'Please pass toISOString() a not empty string', _errorData: { date } }

if (date.toString() === 'Invalid Date') throw { id: 'fln__datetime-local__invalid-date', message: 'Please pass toISOString() a valid date string', _errorData: { date } }

🎁 All Our Packages

  1. @feelinglovelynow/datetime-local: NPMGithub
  2. @feelinglovelynow/dgraph: NPMGithub
  3. @feelinglovelynow/env-write: NPMGithub
  4. @feelinglovelynow/get-form-entries: NPMGithub
  5. @feelinglovelynow/get-relative-time: NPMGithub
  6. @feelinglovelynow/global-style: NPMGithub
  7. @feelinglovelynow/jwt: NPMGithub
  8. @feelinglovelynow/loop-backwards: NPMGithub
  9. @feelinglovelynow/slug: NPMGithub
  10. @feelinglovelynow/svelte-catch: NPMGithub
  11. @feelinglovelynow/svelte-kv: NPMGithub
  12. @feelinglovelynow/svelte-loading-anchor: NPMGithub
  13. @feelinglovelynow/svelte-modal: NPMGithub
  14. @feelinglovelynow/svelte-turnstile: NPMGithub
  15. @feelinglovelynow/toast: NPMGithub

Package Sidebar

Install

npm i @feelinglovelynow/datetime-local

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

22 kB

Total Files

28

Last publish

Collaborators

  • feelinglovelynow