Do not duplicate code. You can put this function a utility class and use it from both places. For an example, see /edx-platform/cms/static/js/utils/get_date.js.