Comments (15)
Could you please write an example of how to replicate it
from instadate.
Problem was in date object.
new Date('2016/10/01 00:00:00')
— works wrong (switch timezone — correct)
new Date(2016, 10, 1, 0, 0, 0)
— works correct (doesn't switch timezone — wrong?)
Can you advise some overall rules for working with Date
object?
from instadate.
Date timezone is in the local timezone of the user. I recommend not using 00:00:00 times since you can lose a day due to daylight saving time. You can use instadate.noon
to prevent that.
from instadate.
So I should to parse time string like 2016/10/01 14:33:13
and set every parameter as argument of new Date()
for correct work? How I can create Date
from string without parsing and without incorrect timezone behaviour?
from instadate.
From where are you getting the dates? You can use the ISO 8601 format to safely set them. Most APIs should be returning that. There is no way around the default timezone when using Date
(or instadate
since it depends heavily on Date
). If timezones are important I recommend checking out Moment.js for that part.
If you are generating dates on client-side JS code I recommend creating a base instadate.noon
date and using instadate to manipulate that (add days, etc).
Sorry for the late replies btw, I have so many GH notifications that I rarely read them..
from instadate.
Oops, I have mistake in example
https://jsbin.com/nudalik/1/edit?js,console
With new Date(2016, 9, 1, 0, 0, 0),
I have same mistake in dates array
from instadate.
I don't want use timezones, but also I don't want any side effects from them
from instadate.
What are you trying to do exactly? If you don't care about timezones instadate should work. Why are you trying to use the format 2016/10/01 00:00:00
?
from instadate.
After using dates()
function I expect to get array of unique dates, but I got duplicates :(
from instadate.
This is because of Daylight savings clock turning on October 30 (http://www.webexhibits.org/daylightsaving/b.html).
You can fix this by using the noon function from instadate:
const dates = instadate.dates(
instadate.noon(new Date('2016/10/01 00:00:00')),
instadate.noon(new Date('2016/11/01 00:00:00'))
);
If you are using the 00 hour of the day then daylight saving can shift it to the previous day.
from instadate.
But setting to noon ruins my time!
from instadate.
You have to find a way around it, as it is a limitation of the JS Date.
from instadate.
But you can avoid this situation, just don't use 24 hours constant as day length. Instead you can use a function like
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
from instadate.
I added tests for the edge case as well as changed all of the adding functions in ce0352a and published it on npm as 0.3.1.
Now I wonder if differenceInX
functions also have that issue. Need to check those later.
Let me know if this fixes your issue
from instadate.
Thanks! It's great, I'll test it on this week
from instadate.
Related Issues (9)
- DifferenceInWeekendDays excludes weekend days HOT 1
- What is the reason there is no differenceInSeconds or differenceInMinutes? HOT 1
- Purpose of this library? HOT 3
- use `files` property in package.json HOT 1
- Holidays? HOT 3
- No `isBefore` and `isAfter` HOT 1
- Set `TZ` locally for tests or convert to UTC
- License HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from instadate.