Skip to content
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

Timezone in usermenu #1764

Merged
merged 13 commits into from
Nov 8, 2019
Prev Previous commit
Next Next commit
Update DateTime component to use useUserTimezone hook
Without the connect function the DateTime component even looks much
cleaner and simpler to understand.
bjoernricks committed Nov 8, 2019
commit 06e2047bca600c70dfbcc9bf1ee4b6d912bde770
20 changes: 8 additions & 12 deletions gsa/src/web/components/date/datetime.js
Original file line number Diff line number Diff line change
@@ -16,19 +16,21 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import {connect} from 'react-redux';

import {dateTimeWithTimeZone, ensureDate} from 'gmp/locale/date';

import {isDefined} from 'gmp/utils/identity';

import {getTimezone} from 'web/store/usersettings/selectors';
import {isDefined, hasValue} from 'gmp/utils/identity';

import PropTypes from 'web/utils/proptypes';
import useUserTimezone from 'web/utils/useUserTimezone';

const DateTime = ({formatter = dateTimeWithTimeZone, timezone, date}) => {
date = ensureDate(date);

const userTimezone = useUserTimezone();

if (!hasValue(timezone)) {
timezone = userTimezone;
}
return !isDefined(date) || !date.isValid() ? null : formatter(date, timezone);
};

@@ -38,10 +40,4 @@ DateTime.propTypes = {
timezone: PropTypes.string,
};

const mapStateToProps = (rootState, ownProps) => ({
timezone: isDefined(ownProps.timezone)
? ownProps.timezone
: getTimezone(rootState),
});

export default connect(mapStateToProps)(DateTime);
export default DateTime;