5 examples of 'moment add' in JavaScript

Every line of 'moment add' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
212export function addMonths(date, amount) {
213 return add(date, amount, "months");
214}
122function add(d, num, unit) {
123
124 if(num < 0){
125 return subtract(d, -(num), unit);
126 }
127
128 unit = moment.normalizeUnits(unit);
129
130
131 if (unit === 'day' ) {
132 d = incrementDays('add')(num, d);
133 // prevent calculation error when break between two working time segments is less than 1 hour
134 } else if (unit === 'hour') {
135 d = addUnit('minute')(num * 60, d);
136 } else if (unit) {
137 d = addUnit(unit)(num, d);
138 }
139 return d;
140}
83function add(time, diff) {
84 var h, m, s;
85 h = time.h + diff.h;
86 m = time.m + diff.m;
87 s = time.s + diff.s;
88
89 m += Math.floor(s/60);
90 s = s % 60;
91
92 h += Math.floor(m/60);
93 m = m % 60;
94
95
96 return {h:h, m:m, s:s} ;
97}
173export function addWeeks (date, amount) {
174 return add(date, amount, 'weeks')
175}
141function add1Day(day) {
142 return moment(day).add(1, "days");
143}

Related snippets