momentjs endOf('month') does not deliver last day of month - node.js

When I invoke the following code
moment('2020-01-01T00:00:00Z').endOf('month').utc().format()
I get the result
'2020-01-01T07:59:59Z'
when I would have expected to see
'2020-01-31T23:59:59Z'
Is this a bug or am I not using the API correctly?

I think the problem is you used endOf before you convert the Date in UTC.
You pass this Date : 2020-01-01T00:00:00Z but the browser understand it with your timezone so the "real date" is 2019-12-31T15:00:00Z.
So you must convert it to UTC first and then proceed your change/call/etc.
So, I tried that and it worked ! Tell me if the problem persist.
moment('2020-01-01T00:00:00Z').utc().endOf('month').format()

Related

why is output of date function on node.js server wrong?

When date was 2018-03-21 19:40, i tried following code
var date = new Date();
console.log(date);
Output :
2018-03-21T16:40:53.755Z
Server is missing for 3 hours as you see. I fixed it by adding 3 hours but I think it's not a good way. How can i fix this problem with better way ?
I don't think the date is incorrect, if you look closely at the format it is being printed, it has a Z at the end, which means:
A suffix which, when applied to a time, denotes a UTC offset of 00:00;
often spoken "Zulu" from the ICAO phonetic alphabet representation of
the letter "Z".
I guess you are in a place separated by 3 hours from UTC.
Node.js uses this format to print Date objects by default, but you can print your local time using toLocaleString():
console.log(date.toLocaleString());
Your server is most likely in another time zone.

Records get skipped Due to timeZone difference between Server and cllients in Nodejs Rethinkdb?

iam filtering some records from my Rethinkdb . the code works just fine when i use the following code . but it works with date only
(new Date(filter.fromdate+' 00:00 GMT+00:00'));
the line above works perfect even after the server is on different region. By using above . It wont skipp any records and time and date just works fine .
but when i use date with time it throws error of rangeError invalid time
I am saving date in rethink in the following format Mon Feb 20 2017 07:25:27 GMT+00:00
SomeHow i just need time with my date to work with the above mentioned code or may be other method can also be used .
Ok, so you need to check if filter.fromdate is with time:
If with time don't add your time and modify it with the proper method of Date , otherwise if is a date without time add your time. And remember you can use momentjs instead of Date to handle dates. Hope help you man.

Timex - Getting the timezone information from DateTime

I am looking for a way to get the timezone information back from a date time.
iex(13)> t = Timex.now("America/Los_Angeles")
#<DateTime(2016-10-23T12:45:34.697369-07:00 America/Los_Angeles)>
iex(14)> Timex.<given_t_return_timezone>??
Given t, I want back "America/Los_Angeles" again.
I knew it had to be easy. Rather than looking at Timex for this, we can simply do:
t.time_zone
This is part of Elixir itself since t is a DateTime.

querysting binding error when using ServiceStack version 4.0.34 and OrmLiteCacheClient

We're getting an "unable to bind to request" when calling a service with the following querystring:
/SomeService?playerid=59326&fromdate=4-1-2014&todate=12-11-2014
We have been using this querysting format for awhile now.
The problem is some either a change in 4.0.34, or something in the OrmLightCacheClient, which we had turned off for awhile and only just recently turned it back on.
If I change the dates to following format, it seems to work.
/SomeService?playerid=59326&fromdate=2014-4-1&todate=2014-12-31.
We can roll with the changed querystring date format for now, but wanted to report the error.
When supplying a date only (i.e. doesn't include a time) it should be unambiguously defined using the YYYY-MM-DD format.

Inverted zone in moment.timezone

I am using nodejs and recently started using moment.timezone to get the timezone offset. I have the following code:
console.log(moment.tz(new Date(), 'Europe/Athens').zone()); // Prints -120
The timezone for 'Europe/Athens' is GMT+2 so i would expect getting '120' and not '-120' and thats what other timezone libraries do.
This issue caused me a serious head scratching bug. It was really easy to fix it once found the problem by just inverting the timezone offset.
Is this a bug on the specific library, or is there a different way to think of zones and offsets? Is there a standard about zone offsets?
This is expected behavior. zone() returns the offset to UTC relative to the selected timezone.
http://momentjs.com/timezone/docs/#/how-to/mutator/

Resources