Git Product home page Git Product logo

ts-luxon's Introduction

TS Luxon

MIT License Build Status NPM version Coverage Status PRs welcome Size

TS Luxon is a library for working with dates and times in Javscript and Typescript.

This repo was initially created by GillesDebunne which of course started from Luxon itself.

Many thanks to both of them for this fantastic work.

I decided to fork his work, because we don't know for sure if and when Luxon will adopt this source.

I realized moment wasn't suitable anymore for my projects, but I couldn't wait to have a more stable version and at this time Luxon (v 1.25.0) had structural issues, which resulted in errors in my Angular projects.

Upgrading to 4.x

See the docs page

DateTime.now().setZone('America/New_York').minus({ weeks: 1 }).endOf('day').toISO();

Features

  • DateTime, Duration, and Interval types.
  • Immutable, chainable, unambiguous API.
  • Parsing and formatting for common and custom formats.
  • Native time zone and Intl support (no locale or tz files).

Usage

Via npm

npm i ts-luxon --save

then

import {DateTime} from "ts-luxon";

const myDto = DateTime.local();

Bundle / UMD

You can download the umd bundle from here:

DOCS

See the docs page

and the demo page

more example will be added! For suggestions open an issue or a PR (yes, even on the demo site if you want)!

Special thanks

Jetbrains is now supporting this library with an open-source license, which will allow a better code! 🎉

jetbrains-logo


Thanks to fire332 for his contribution about package.json

Development

Please, read the CONTRIBUTING.md you can find in the master branch.

ts-luxon's People

Contributors

kikocosmetics avatar tonysamperi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

taisho wsw70 btd1337

ts-luxon's Issues

Incorrect NPM link on doc site

Describe the bug
Doc site shows npm install --save luxon when it should be npm install --save ts-luxon

I'd put in a PR myself but I couldn't find where the docs were located here or in your portfolio repo (repo looks to be bundled for prod prior to push unlike the old/ directory of your previous portfolio).

Just had to add that I really appreciate your TypeScript conversion of the repo since the DefinitelyTyped @types/luxon does not contain the complete types (ex. properties on the DateTime object).

Import issues in modern Node versions due to improperly declared package.json

Describe the bug

import { DateTime } from 'ts-luxon';
         ^^^^^^^^
SyntaxError: The requested module 'ts-luxon' does not provide an export named 'DateTime'

ts-luxon needs to have a properly declared exports field in package.json for Node to use the ESM bundle. Additionally, the exports need to have the correct file extension to avoid incorrect interpretation.

Example:

{
    "type": "commonjs",
    "exports": {
        ".": {
            "types": "./dist/index.d.ts",
            "import": "./dist/ts-luxon.es6.mjs", // NOTE: .mjs file extension
            "default": "./dist/ts-luxon.umd.js" // NOTE: interpreted as commonjs due to `type` field
        }
    }
}

Note that the example has this issue.
See: https://publint.dev/[email protected]

To Reproduce
https://stackblitz.com/edit/stackblitz-starters-gpzsez?file=index.js

Actual vs Expected behavior
No import errors.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome 125.0.6368.2 (Official Build) dev (64-bit)
  • Luxon version: 4.5.2

Feature Request

Would it be possible to add the following functions to the library?

  • isFuture
  • isPast
  • isTheSameDay
  • isTheSameMonth
  • isTheSameYear

These last 3 should compare the day, month, and year as a whole

Thanks in advance!

Documentation update | nullOnInvalid

Describe the issue
The documentation of some methods - listed below - does not match the implementation. The documentation lists one can pass @param {boolean} [options.nullOnInvalid=false] - return null on invalid values instead of throwing an error; however, this property does not exist on the type of DateTimeOptions which is used to type the [options|opts] parameter used in most DateTime class methods.

Instances of [options|opts].nullOnInvalid being referenced

Parsing dates generated by the browser creates invalid datetimes cause of NNBSP

Describe the bug
After the last update of Chromium 110, generated Dates with Meridiem can't be parsed correctly due to NNBSP

see tonysamperi/ngx-mat-timepicker#51

To Reproduce

    const dto = DateTime.fromFormat("3:22 AM", "h:m a", {
        numberingSystem: "latn",
        locale: "en-US"
    });

Actual vs Expected behavior
dto is expected to be valid, but it is invalid due to parse error

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser: all chromium based browsers above v 109
  • ts-luxon version: 4.0.0 (but every version is affected)

Missing files warning in build

Describe the bug
There are missing files errors in the build log.

WARNING in ../node_modules/ts-luxon/dist/ts-luxon.es6.js
Module Warning (from ../node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'node_modules/src/zones/fixedOffsetZone.ts' file: Error: ENOENT: no such file or directory, open...

To Reproduce
Build the project with newest [email protected]

Actual vs Expected behavior
Build without warnings and errors.

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser Crome
  • Luxon version 4.2.2

Additional context
It was not there before the bugfix. I am doing weekly updates.

Wrong path to typings in 4.3.0 package.json

In the package json it says:

"typings": "dist/index.d.ts",

but in 4.3.0 the actual index.d.ts has been moved to here:

"dist/lib/index.d.ts"

Without adjusting the package.json information.

This leads to the following error in our builds: error TS7016: Could not find a declaration file for module 'ts-luxon'

[REQUEST] Deno Support

Hi @tonysamperi,

Firstly, congratulations on this great work; ts-luxon is truly amazing.

I feel that a date library like ts-luxon is missing in the Deno ecosystem. It would be great if you could consider sharing your library on Deno Land.

Deno + TS-Luxon is the perfect combination, and you could make this possible.

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.