Skip to content

Instantly share code, notes, and snippets.

@Sivli-Embir
Last active April 5, 2017 18:37
Show Gist options
  • Save Sivli-Embir/95e37b7bc2736bcc46715758c2a3ffd9 to your computer and use it in GitHub Desktop.
Save Sivli-Embir/95e37b7bc2736bcc46715758c2a3ffd9 to your computer and use it in GitHub Desktop.
import {getCurrentWeek} from 'weekSolution';
// Friday: -2
getCurrentWeek(-2)
// Saturday: -1
getCurrentWeek(-2)
// Sunday: 0
getCurrentWeek(0)
// Monday: 1
getCurrentWeek(1)
// Tuesday: 2
getCurrentWeek(2)
// Wednesday: 3
getCurrentWeek(3)
// Thursday: 4
getCurrentWeek(4)
import moment from 'moment';
moment.defineLocale('custom-0', {parentLocale: 'en', week:{dow : 0}});
moment.defineLocale('custom-1', {parentLocale: 'en', week:{dow : 1}});
moment.defineLocale('custom-2', {parentLocale: 'en', week:{dow : 2}});
moment.defineLocale('custom-3', {parentLocale: 'en', week:{dow : 3}});
moment.defineLocale('custom-4', {parentLocale: 'en', week:{dow : 4}});
moment.defineLocale('custom--2', {parentLocale: 'en', week:{dow : -2}});
moment.defineLocale('custom--1', {parentLocale: 'en', week:{dow : -1}});
export function getCurrentWeek(dayOffSet) {
moment.locale(`custom-${dayOffSet}`) //always set this to override locale settings.
let date = moment()
return {
year: date.year(),
week: date.week()
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment