Coder Social home page Coder Social logo

Comments (7)

eight04 avatar eight04 commented on June 8, 2024 1

I'm not sure what you are going to achieve.

If you want to use 1976-11-14T07:05:58+01:00 as default value, you can convert the date string into a date object: https://plnkr.co/edit/9YRgQClGD9gpVQSeLlzT?p=preview

If you want to create a datetime input with specific timezone (+0100), currently you can't. There is only a datetime-utc flag to use +0000 as timezone.

And here is why you got the date of the day:

  1. The parser raised mismatch error when parsing a date string with incorrect timezone.
  2. The directive tried to revert the input to previous state when getting a parsing error.
  3. The date was set to its initial value new Date().

from angular-datetime.

marechalsamuel avatar marechalsamuel commented on June 8, 2024

After searching and testing, it seems parsing gets an error on timezone whenever it's not the default timezone or the one that is set. Getting this error message : Pattern value mismatch
Here is the test :
https://plnkr.co/edit/SBZDc5CaaFLsJ9eKzuAE?p=preview

from angular-datetime.

marechalsamuel avatar marechalsamuel commented on June 8, 2024

Converting my string into a date object will do it.
I guess parsing timezone is work in progress, maybe meanwhile it would be convenient to add a note in the readme about ZZ on this point ?
Thank you anyway for your reactivity and also for you work !

from angular-datetime.

eight04 avatar eight04 commented on June 8, 2024

There were some discussions to make timezone "editable", but this feature is rarely used. Most of the time we only save the date into database without timezone information, and display the date to users in their local timezone. If timezone information is needed, we use another field to record it.

However, it would be good if we can make timezone "parsable", which should work like this:

datestr = "1976-11-14T07:05:58+01:00";
parser = datetime("yyyy-MM-ddTHH:mm:ssZZ");
date = parser.parse(datestr, true).getDate();	// a flag allowing the parser to switch the timezone automatically

date.getTime() == new Date(datestr).getTime();	// true
parser.inTimezone("+01:00");	// true

from angular-datetime.

marechalsamuel avatar marechalsamuel commented on June 8, 2024

For information, we found a neat solution to handle the issue making a directive with $parsers and $formatters having a priority of 101 (superior to this library)

https://plnkr.co/edit/g2tPcae2mfdp3PHo9HZ1?p=preview

I guess this could be directly done inside the library.

from angular-datetime.

eight04 avatar eight04 commented on June 8, 2024

You will get the date in local timezone with that code, also the colon : is missing.

If timezone doesn't matter, I would do something like this:
https://plnkr.co/edit/MRAoBt8Cam6YbmlvHgkb?p=preview

from angular-datetime.

eight04 avatar eight04 commented on June 8, 2024

Now you can use datetime-zone to specify a custom timezone.

from angular-datetime.

Related Issues (20)

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.