-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use alongside moment-timezone? #5
Comments
Thanks for raising an issue @rafakato I haven't tried using alongside moment-timezone. Could you possibly provide more information about what you're trying to do and how exactly it's not working? |
Hi @lennym, I was using the moment-timezone in one of my projects because I need to display the datetime in a certain timezone, and their documentation it says to use like this:
But when I try to load your plugin it does not extends the moment()... For now I removed the moment-timezone in the module I'll use your plugin, but if the two works together it will be best for me. |
I just tried running this:
and it seemed to work mostly ok. There does seem to be a bug with detecting if a current time is a "working time" when the timezone has been set though (in particular, it tests the UTC time and not the local time). I shall look into that. |
In my application I load the moment-timezone first and expose it in a module, and after I load the moment-business-time where I need it. Can you check if this works too? |
Since both my module, and moment-timezone modify the underlying moment object, then as long as require.resolve resolves to the same instance of moment in each case then everything should work fine. If it is not working then it's likely a result of your install paths for each module. Try installing moment as a top-level dependency of your project, and running |
I have this module that exposes the moment-timezone: 'use strict';
const moment = require('moment-timezone');
module.exports = function (value, tz) {
if (tz === undefined) {
tz = 'America/Sao_Paulo';
}
if (tz) {
return moment(value).tz(tz);
} else {
return moment(value);
}
}; |
I see no particular reason that should cause any problem, aside from possibly the |
I'll try to install it as a top-level dependency. The const is no problem, I use iojs in this project :) |
I was wondering the same thing. I decided to fork the repository and replace the dependency on moment with moment-timezone. Besides this, I updated dependencies to the latest and add a checkZone that sets the timezone to UTC when no tz.defaultZone is set. My fork is here: https://github.com/codeforeurope/moment-business-time/ |
For a specific time-zone, you could use the following: var date = new Date(new Date().toLocaleString('en-US', { timeZone: 'America/New_York' }));
var result = moment(date).isWorkingTime(); |
Time ago I had the same problem, how to use tz with moment-business-time to get time differences. I found this solution for now first you need to get the offset timezone
timezone could be 'America/Bogota' or whatever So when you are going to use moment-business-time, use in other variable
add configuration to your business object then create your moments objects and add the offset
finally use 'moment-business-time' methods normally |
Still not working :) The proposed fork does not solve the problem? |
For now, my temporary solution is use self-written function: const fix_timezone = (datetime, time_zone) => {
const offset = moment_tz.tz.zone(time_zone).parse();
// console.log(offset)
return moment(datetime.utcOffset(-offset)).add(offset, 'minutes')
} Warning! It was not tested for all cases, but for one timezone :) Code example: |
I tried to use your plugin with moment-timezone, but it didn't worked.
Have you ever tried?
Thanks
The text was updated successfully, but these errors were encountered: