Skip to content

Instantly share code, notes, and snippets.

@Sivli-Embir

Sivli-Embir/example.js

Last active Apr 5, 2017
Embed
What would you like to do?
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