How to use endDate method in Best

Best JavaScript code snippet using best

DateUtil.js

Source:DateUtil.js Github

copy

Full Screen

1/**2 * used in Core to convert the options into a volatile variable3 * 4 * @param {function} moment5 * @param {Object} body6 * @param {Array | Object} hiddenDates7 * @returns {number}8 */9exports.convertHiddenOptions = function(moment, body, hiddenDates) {10 if (hiddenDates && !Array.isArray(hiddenDates)) {11 return exports.convertHiddenOptions(moment, body, [hiddenDates])12 }13 body.hiddenDates = [];14 if (hiddenDates) {15 if (Array.isArray(hiddenDates) == true) {16 for (var i = 0; i < hiddenDates.length; i++) {17 if (hiddenDates[i].repeat === undefined) {18 var dateItem = {};19 dateItem.start = moment(hiddenDates[i].start).toDate().valueOf();20 dateItem.end = moment(hiddenDates[i].end).toDate().valueOf();21 body.hiddenDates.push(dateItem);22 }23 }24 body.hiddenDates.sort(function (a, b) {25 return a.start - b.start;26 }); // sort by start time27 }28 }29};30/**31 * create new entrees for the repeating hidden dates32 *33 * @param {function} moment34 * @param {Object} body35 * @param {Array | Object} hiddenDates36 * @returns {null}37 */38exports.updateHiddenDates = function (moment, body, hiddenDates) {39 if (hiddenDates && !Array.isArray(hiddenDates)) {40 return exports.updateHiddenDates(moment, body, [hiddenDates])41 }42 if (hiddenDates && body.domProps.centerContainer.width !== undefined) {43 exports.convertHiddenOptions(moment, body, hiddenDates);44 var start = moment(body.range.start);45 var end = moment(body.range.end);46 var totalRange = (body.range.end - body.range.start);47 var pixelTime = totalRange / body.domProps.centerContainer.width;48 for (var i = 0; i < hiddenDates.length; i++) {49 if (hiddenDates[i].repeat !== undefined) {50 var startDate = moment(hiddenDates[i].start);51 var endDate = moment(hiddenDates[i].end);52 if (startDate._d == "Invalid Date") {53 throw new Error("Supplied start date is not valid: " + hiddenDates[i].start);54 }55 if (endDate._d == "Invalid Date") {56 throw new Error("Supplied end date is not valid: " + hiddenDates[i].end);57 }58 var duration = endDate - startDate;59 if (duration >= 4 * pixelTime) {60 var offset = 0;61 var runUntil = end.clone();62 switch (hiddenDates[i].repeat) {63 case "daily": // case of time64 if (startDate.day() != endDate.day()) {65 offset = 1;66 }67 startDate.dayOfYear(start.dayOfYear());68 startDate.year(start.year());69 startDate.subtract(7,'days');70 endDate.dayOfYear(start.dayOfYear());71 endDate.year(start.year());72 endDate.subtract(7 - offset,'days');73 runUntil.add(1, 'weeks');74 break;75 case "weekly":76 var dayOffset = endDate.diff(startDate,'days');77 var day = startDate.day();78 // set the start date to the range.start79 startDate.date(start.date());80 startDate.month(start.month());81 startDate.year(start.year());82 endDate = startDate.clone();83 // force84 startDate.day(day);85 endDate.day(day);86 endDate.add(dayOffset,'days');87 startDate.subtract(1,'weeks');88 endDate.subtract(1,'weeks');89 runUntil.add(1, 'weeks');90 break;91 case "monthly":92 if (startDate.month() != endDate.month()) {93 offset = 1;94 }95 startDate.month(start.month());96 startDate.year(start.year());97 startDate.subtract(1,'months');98 endDate.month(start.month());99 endDate.year(start.year());100 endDate.subtract(1,'months');101 endDate.add(offset,'months');102 runUntil.add(1, 'months');103 break;104 case "yearly":105 if (startDate.year() != endDate.year()) {106 offset = 1;107 }108 startDate.year(start.year());109 startDate.subtract(1,'years');110 endDate.year(start.year());111 endDate.subtract(1,'years');112 endDate.add(offset,'years');113 runUntil.add(1, 'years');114 break;115 default:116 console.log("Wrong repeat format, allowed are: daily, weekly, monthly, yearly. Given:", hiddenDates[i].repeat);117 return;118 }119 while (startDate < runUntil) {120 body.hiddenDates.push({start: startDate.valueOf(), end: endDate.valueOf()});121 switch (hiddenDates[i].repeat) {122 case "daily":123 startDate.add(1, 'days');124 endDate.add(1, 'days');125 break;126 case "weekly":127 startDate.add(1, 'weeks');128 endDate.add(1, 'weeks');129 break;130 case "monthly":131 startDate.add(1, 'months');132 endDate.add(1, 'months');133 break;134 case "yearly":135 startDate.add(1, 'y');136 endDate.add(1, 'y');137 break;138 default:139 console.log("Wrong repeat format, allowed are: daily, weekly, monthly, yearly. Given:", hiddenDates[i].repeat);140 return;141 }142 }143 body.hiddenDates.push({start: startDate.valueOf(), end: endDate.valueOf()});144 }145 }146 }147 // remove duplicates, merge where possible148 exports.removeDuplicates(body);149 // ensure the new positions are not on hidden dates150 var startHidden = exports.isHidden(body.range.start, body.hiddenDates);151 var endHidden = exports.isHidden(body.range.end,body.hiddenDates);152 var rangeStart = body.range.start;153 var rangeEnd = body.range.end;154 if (startHidden.hidden == true) {rangeStart = body.range.startToFront == true ? startHidden.startDate - 1 : startHidden.endDate + 1;}155 if (endHidden.hidden == true) {rangeEnd = body.range.endToFront == true ? endHidden.startDate - 1 : endHidden.endDate + 1;}156 if (startHidden.hidden == true || endHidden.hidden == true) {157 body.range._applyRange(rangeStart, rangeEnd);158 }159 }160};161/**162 * remove duplicates from the hidden dates list. Duplicates are evil. They mess everything up.163 * Scales with N^2164 *165 * @param {Object} body166 */167exports.removeDuplicates = function(body) {168 var hiddenDates = body.hiddenDates;169 var safeDates = [];170 for (var i = 0; i < hiddenDates.length; i++) {171 for (var j = 0; j < hiddenDates.length; j++) {172 if (i != j && hiddenDates[j].remove != true && hiddenDates[i].remove != true) {173 // j inside i174 if (hiddenDates[j].start >= hiddenDates[i].start && hiddenDates[j].end <= hiddenDates[i].end) {175 hiddenDates[j].remove = true;176 }177 // j start inside i178 else if (hiddenDates[j].start >= hiddenDates[i].start && hiddenDates[j].start <= hiddenDates[i].end) {179 hiddenDates[i].end = hiddenDates[j].end;180 hiddenDates[j].remove = true;181 }182 // j end inside i183 else if (hiddenDates[j].end >= hiddenDates[i].start && hiddenDates[j].end <= hiddenDates[i].end) {184 hiddenDates[i].start = hiddenDates[j].start;185 hiddenDates[j].remove = true;186 }187 }188 }189 }190 for (i = 0; i < hiddenDates.length; i++) {191 if (hiddenDates[i].remove !== true) {192 safeDates.push(hiddenDates[i]);193 }194 }195 body.hiddenDates = safeDates;196 body.hiddenDates.sort(function (a, b) {197 return a.start - b.start;198 }); // sort by start time199};200exports.printDates = function(dates) {201 for (var i =0; i < dates.length; i++) {202 console.log(i, new Date(dates[i].start),new Date(dates[i].end), dates[i].start, dates[i].end, dates[i].remove);203 }204};205/**206 * Used in TimeStep to avoid the hidden times.207 * @param {function} moment208 * @param {TimeStep} timeStep209 * @param {Date} previousTime210 */211exports.stepOverHiddenDates = function(moment, timeStep, previousTime) {212 var stepInHidden = false;213 var currentValue = timeStep.current.valueOf();214 for (var i = 0; i < timeStep.hiddenDates.length; i++) {215 var startDate = timeStep.hiddenDates[i].start;216 var endDate = timeStep.hiddenDates[i].end;217 if (currentValue >= startDate && currentValue < endDate) {218 stepInHidden = true;219 break;220 }221 }222 if (stepInHidden == true && currentValue < timeStep._end.valueOf() && currentValue != previousTime) {223 var prevValue = moment(previousTime);224 var newValue = moment(endDate);225 //check if the next step should be major226 if (prevValue.year() != newValue.year()) {timeStep.switchedYear = true;}227 else if (prevValue.month() != newValue.month()) {timeStep.switchedMonth = true;}228 else if (prevValue.dayOfYear() != newValue.dayOfYear()) {timeStep.switchedDay = true;}229 timeStep.current = newValue;230 }231};232///**233// * Used in TimeStep to avoid the hidden times.234// * @param timeStep235// * @param previousTime236// */237//exports.checkFirstStep = function(timeStep) {238// var stepInHidden = false;239// var currentValue = timeStep.current.valueOf();240// for (var i = 0; i < timeStep.hiddenDates.length; i++) {241// var startDate = timeStep.hiddenDates[i].start;242// var endDate = timeStep.hiddenDates[i].end;243// if (currentValue >= startDate && currentValue < endDate) {244// stepInHidden = true;245// break;246// }247// }248//249// if (stepInHidden == true && currentValue <= timeStep._end.valueOf()) {250// var newValue = moment(endDate);251// timeStep.current = newValue.toDate();252// }253//};254/**255 * replaces the Core toScreen methods256 *257 * @param {vis.Core} Core258 * @param {Date} time259 * @param {number} width260 * @returns {number}261 */262exports.toScreen = function (Core, time, width) {263 var conversion;264 if (Core.body.hiddenDates.length == 0) {265 conversion = Core.range.conversion(width);266 return (time.valueOf() - conversion.offset) * conversion.scale;267 } else {268 var hidden = exports.isHidden(time, Core.body.hiddenDates);269 if (hidden.hidden == true) {270 time = hidden.startDate;271 }272 var duration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end);273 if (time < Core.range.start) {274 conversion = Core.range.conversion(width, duration);275 var hiddenBeforeStart = exports.getHiddenDurationBeforeStart(Core.body.hiddenDates, time, conversion.offset);276 time = Core.options.moment(time).toDate().valueOf();277 time = time + hiddenBeforeStart;278 return -(conversion.offset - time.valueOf()) * conversion.scale;279 280 } else if (time > Core.range.end) {281 var rangeAfterEnd = {start: Core.range.start, end: time};282 time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, rangeAfterEnd, time);283 conversion = Core.range.conversion(width, duration);284 return (time.valueOf() - conversion.offset) * conversion.scale;285 } else {286 time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, Core.range, time);287 conversion = Core.range.conversion(width, duration);288 return (time.valueOf() - conversion.offset) * conversion.scale;289 }290 }291 };292/**293 * Replaces the core toTime methods294 *295 * @param {vis.Core} Core296 * @param {number} x297 * @param {number} width298 * @returns {Date}299 */300exports.toTime = function(Core, x, width) {301 if (Core.body.hiddenDates.length == 0) {302 var conversion = Core.range.conversion(width);303 return new Date(x / conversion.scale + conversion.offset);304 }305 else {306 var hiddenDuration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end);307 var totalDuration = Core.range.end - Core.range.start - hiddenDuration;308 var partialDuration = totalDuration * x / width;309 var accumulatedHiddenDuration = exports.getAccumulatedHiddenDuration(Core.body.hiddenDates, Core.range, partialDuration);310 return new Date(accumulatedHiddenDuration + partialDuration + Core.range.start);311 }312};313/**314 * Support function315 *316 * @param {Array.<{start: Window.start, end: *}>} hiddenDates317 * @param {number} start318 * @param {number} end319 * @returns {number}320 */321exports.getHiddenDurationBetween = function(hiddenDates, start, end) {322 var duration = 0;323 for (var i = 0; i < hiddenDates.length; i++) {324 var startDate = hiddenDates[i].start;325 var endDate = hiddenDates[i].end;326 // if time after the cutout, and the327 if (startDate >= start && endDate < end) {328 duration += endDate - startDate;329 }330 }331 return duration;332};333/**334 * Support function335 *336 * @param {Array.<{start: Window.start, end: *}>} hiddenDates337 * @param {number} start338 * @param {number} end339 * @returns {number}340 */341exports.getHiddenDurationBeforeStart = function (hiddenDates, start, end) {342 var duration = 0;343 for (var i = 0; i < hiddenDates.length; i++) {344 var startDate = hiddenDates[i].start;345 var endDate = hiddenDates[i].end;346 if (startDate >= start && endDate <= end) {347 duration += endDate - startDate;348 }349 }350 return duration;351};352/**353 * Support function354 * @param {function} moment355 * @param {Array.<{start: Window.start, end: *}>} hiddenDates356 * @param {{start: number, end: number}} range357 * @param {Date} time358 * @returns {number}359 */360exports.correctTimeForHidden = function(moment, hiddenDates, range, time) {361 time = moment(time).toDate().valueOf();362 time -= exports.getHiddenDurationBefore(moment, hiddenDates,range,time);363 return time;364};365exports.getHiddenDurationBefore = function(moment, hiddenDates, range, time) {366 var timeOffset = 0;367 time = moment(time).toDate().valueOf();368 for (var i = 0; i < hiddenDates.length; i++) {369 var startDate = hiddenDates[i].start;370 var endDate = hiddenDates[i].end;371 // if time after the cutout, and the372 if (startDate >= range.start && endDate < range.end) {373 if (time >= endDate) {374 timeOffset += (endDate - startDate);375 }376 }377 }378 return timeOffset;379};380/**381 * sum the duration from start to finish, including the hidden duration,382 * until the required amount has been reached, return the accumulated hidden duration383 * @param {Array.<{start: Window.start, end: *}>} hiddenDates384 * @param {{start: number, end: number}} range385 * @param {number} [requiredDuration=0]386 * @returns {number}387 */388exports.getAccumulatedHiddenDuration = function(hiddenDates, range, requiredDuration) {389 var hiddenDuration = 0;390 var duration = 0;391 var previousPoint = range.start;392 //exports.printDates(hiddenDates)393 for (var i = 0; i < hiddenDates.length; i++) {394 var startDate = hiddenDates[i].start;395 var endDate = hiddenDates[i].end;396 // if time after the cutout, and the397 if (startDate >= range.start && endDate < range.end) {398 duration += startDate - previousPoint;399 previousPoint = endDate;400 if (duration >= requiredDuration) {401 break;402 }403 else {404 hiddenDuration += endDate - startDate;405 }406 }407 }408 return hiddenDuration;409};410/**411 * used to step over to either side of a hidden block. Correction is disabled on tablets, might be set to true412 * @param {Array.<{start: Window.start, end: *}>} hiddenDates413 * @param {Date} time414 * @param {number} direction415 * @param {boolean} correctionEnabled416 * @returns {Date|number}417 */418exports.snapAwayFromHidden = function(hiddenDates, time, direction, correctionEnabled) {419 var isHidden = exports.isHidden(time, hiddenDates);420 if (isHidden.hidden == true) {421 if (direction < 0) {422 if (correctionEnabled == true) {423 return isHidden.startDate - (isHidden.endDate - time) - 1;424 }425 else {426 return isHidden.startDate - 1;427 }428 }429 else {430 if (correctionEnabled == true) {431 return isHidden.endDate + (time - isHidden.startDate) + 1;432 }433 else {434 return isHidden.endDate + 1;435 }436 }437 }438 else {439 return time;440 }441};442/**443 * Check if a time is hidden444 *445 * @param {Date} time446 * @param {Array.<{start: Window.start, end: *}>} hiddenDates447 * @returns {{hidden: boolean, startDate: Window.start, endDate: *}}448 */449exports.isHidden = function(time, hiddenDates) {450 for (var i = 0; i < hiddenDates.length; i++) {451 var startDate = hiddenDates[i].start;452 var endDate = hiddenDates[i].end;453 if (time >= startDate && time < endDate) { // if the start is entering a hidden zone454 return {hidden: true, startDate: startDate, endDate: endDate};455 }456 }457 return {hidden: false, startDate: startDate, endDate: endDate};...

Full Screen

Full Screen

eventsDate.pipe.ts

Source:eventsDate.pipe.ts Github

copy

Full Screen

1import { Pipe, PipeTransform } from '@angular/core';2import * as moment from 'moment';3@Pipe({ name: 'eventsDate' })4export class EventsDatePipe implements PipeTransform { 5 transform(value: string, eventEndDate: string, localeAndDateFormat: any) { 6 let date = '';7 if (value !== undefined && eventEndDate !== undefined && localeAndDateFormat !== undefined) { 8 let startDate = moment.utc(value).locale(localeAndDateFormat.locale); 9 let endDate = moment.utc(eventEndDate).locale(localeAndDateFormat.locale);10 11 12 if (startDate.get('year') == endDate.get('year')) {13 if (startDate.get('month') == endDate.get('month')) {14 if (startDate.get('date') == endDate.get('date')) {15 date = startDate.format(localeAndDateFormat.format);16 17 18 } else {19 date = startDate.format('MMMM DD') + '-' + endDate.format('DD') + ', ' + startDate.get('year'); 20 } 21 } else {22 date = startDate.format('MMMM DD') + '-' + endDate.format('MMMM DD') + ', ' + startDate.get('year');23 } 24 } else { 25 date = startDate.format(localeAndDateFormat.format) + '-' + endDate.format(localeAndDateFormat.format);26 }27 if (localeAndDateFormat.locale == 'es') {28 date = date.charAt(0).toUpperCase() + date.slice(1);29 }30 31 if (localeAndDateFormat.locale == 'ja' || localeAndDateFormat.locale == 'zh') {32 if (startDate.get('year') == endDate.get('year')) {33 if (startDate.get('month') == endDate.get('month')) {34 if (startDate.get('date') == endDate.get('date')) {35 date = startDate.format(localeAndDateFormat.format);36 } else {37 date = startDate.get('year')+"年"+startDate.format('M')+'月'+startDate.format('D') + '-' + endDate.format('D') + '日'; 38 39 } 40 } else {41 date = startDate.get('year')+"年"+startDate.format('M')+'月'+startDate.format('D') + '日'+ '-' +endDate.format('M')+'月'+endDate.format('D') + '日';42 43 } 44 } else { 45 date = startDate.get('year')+"年"+startDate.format('M')+'月'+startDate.format('D') + '日'+ '-'+endDate.get('year')+"年" +endDate.format('M')+'月'+endDate.format('D') + '日';46 }47 }48 if (localeAndDateFormat.locale == 'fr') {49 if (startDate.get('year') == endDate.get('year')) {50 if (startDate.get('month') == endDate.get('month')) {51 if (startDate.get('date') == endDate.get('date')) {52 date = startDate.format(localeAndDateFormat.format);53 54 } else {55 date = startDate.format('DD') + ' - ' + endDate.format('DD') + ' '+startDate.format('MMMM') +' ' + startDate.get('year'); 56 } 57 } else {58 date = startDate.format('DD') + ' '+startDate.format('MMMM') + ' - ' + endDate.format('DD') +' ' +endDate.format('MMMM')+' ' +startDate.get('year'); 59 60 } 61 } else { 62 date = startDate.format('DD') + ' '+startDate.format('MMMM') +' ' +startDate.get('year')+ ' - ' + endDate.format('DD') +' ' +endDate.format('MMMM')+' ' +endDate.get('year'); 63 }64 }65 if (localeAndDateFormat.locale == 'ru') {66 if (startDate.get('year') == endDate.get('year')) {67 if (startDate.get('month') == endDate.get('month')) {68 if (startDate.get('date') == endDate.get('date')) {69 date = startDate.format(localeAndDateFormat.format);70 71 } else {72 date = startDate.format('D') + '-' + endDate.format('D') + ' '+startDate.format('MMMM') +' ' + startDate.get('year'); 73 } 74 } else {75 date = startDate.format('D') + ' '+startDate.format('MMMM') + '-' + endDate.format('D') +' ' +endDate.format('MMMM')+' ' +startDate.get('year'); 76 77 } 78 } else { 79 date = startDate.format('D') + ' '+startDate.format('MMMM') +' ' +startDate.get('year')+ '-' + endDate.format('D') +' ' +endDate.format('MMMM')+' ' +endDate.get('year'); 80 }81 }82 if (localeAndDateFormat.locale == 'ar') {83 startDate = moment.utc(value).locale('ar-tn'); 84 endDate = moment.utc(eventEndDate).locale('ar-tn');85 if (startDate.get('year') == endDate.get('year')) {86 if (startDate.get('month') == endDate.get('month')) {87 if (startDate.get('date') == endDate.get('date')) {88 89 date =startDate.get('year') +"/"+(startDate.get('month') + 1) +"/"+ ('0' + startDate.get('date')).slice(-2);90 91 } else {92 date = ('0' + endDate.get('date')).slice(-2) + ' - ' + ('0' + startDate.get('date')).slice(-2) + ' '+startDate.format('MMMM') +' ' + startDate.get('year'); 93 } 94 } else {95 date = ('0' + startDate.get('date')).slice(-2) + ' '+startDate.format('MMMM') +' إلى '+ ('0' + endDate.get('date')).slice(-2) +' ' +endDate.format('MMMM')+' ' +startDate.get('year'); 96 97 } 98 } else { 99 date = ('0' + startDate.get('date')).slice(-2) + ' '+startDate.format('MMMM') +' ' +startDate.get('year')+' إلى '+ ('0' + endDate.get('date')).slice(-2) +' ' +endDate.format('MMMM')+' ' +endDate.get('year'); 100 } 101}102if (localeAndDateFormat.locale == 'pt') {103 if (startDate.get('year') == endDate.get('year')) {104 if (startDate.get('month') == endDate.get('month')) {105 if (startDate.get('date') == endDate.get('date')) {106 date = startDate.format('DD') + ' de '+startDate.format('MMMM') +' de ' + startDate.get('year'); 107 108 } else {109 date = startDate.format('DD') + ' - ' + endDate.format('DD') + ' de '+startDate.format('MMMM') +' de ' + startDate.get('year'); 110 } 111 } else {112 date = startDate.format('DD') + ' de '+startDate.format('MMMM') + ' - ' + endDate.format('DD') +' de ' +endDate.format('MMMM')+' de ' +startDate.get('year'); 113 114 } 115 } else { 116 date = startDate.format('DD') + ' de '+startDate.format('MMMM') +' de ' +startDate.get('year')+ ' - ' + endDate.format('DD') +' de ' +endDate.format('MMMM')+' de ' +endDate.get('year'); 117 }118}119if (localeAndDateFormat.locale == 'vi') {120 let startMonth = startDate.format('MMMM');121 let endMonth = endDate.format('MMMM');122 startMonth = startMonth.charAt(0).toUpperCase() + startMonth.slice(1);123 endMonth = endMonth.charAt(0).toUpperCase() + endMonth.slice(1);124 if (startDate.get('year') == endDate.get('year')) {125 if (startDate.get('month') == endDate.get('month')) {126 if (startDate.get('date') == endDate.get('date')) {127 date = startDate.format('D ') + startMonth+' Năm ' + startDate.get('year'); 128 } else {129 date = 'Ngày '+ startDate.format('D') +'-' + endDate.format('D ')+startMonth +' Năm ' + startDate.get('year'); 130 131 } 132 } else {133 date = 'Ngày '+ startDate.format('D ') +startMonth + ' - ' +'Ngày '+ endDate.format('D ') +endMonth+' Năm ' +startDate.get('year'); 134 135 } 136} else { 137 date = 'Ngày '+ startDate.format('D ') +startMonth +' Năm ' +startDate.get('year')+ ' - ' +'Ngày '+ endDate.format('D ') +endMonth+' Năm ' +endDate.get('year'); 138}139}140if (localeAndDateFormat.locale == 'sq' || localeAndDateFormat.locale == 'ro' || localeAndDateFormat.locale == 'bg' || localeAndDateFormat.locale == 'pl' || localeAndDateFormat.locale == 'tr' || localeAndDateFormat.locale == 'th' || localeAndDateFormat.locale == 'id' || localeAndDateFormat.locale == 'mk') {141 142 let startYear = startDate.get('year');143 let endYear = endDate.get('year');144 if(localeAndDateFormat.locale == 'th')145 {146 startYear = startYear + 543;147 endYear = endYear + 543;148 }149 let startMonth = startDate.format('MMMM');150 let endMonth = endDate.format('MMMM');151 if(localeAndDateFormat.locale != 'tr')152 {153 startMonth = startDate.format('MMMM').toLowerCase();154 endMonth = endDate.format('MMMM').toLowerCase();155 }156 if (startDate.get('year') == endDate.get('year')) {157 if (startDate.get('month') == endDate.get('month')) {158 if (startDate.get('date') == endDate.get('date')) {159 if(localeAndDateFormat.locale != 'tr')160 date = startDate.format(localeAndDateFormat.format).toLowerCase();161 if(localeAndDateFormat.locale == 'th')162 date = 'วันที่ ' + startDate.format('DD')+ startMonth + ' ' + startYear; 163 } else {164 date = startDate.format('DD') + '-' +endDate.format('DD')+ ' '+startMonth+ ' ' + startYear; 165 } 166 } else {167 date = startDate.format('DD')+ ' ' + startMonth + '-' + endDate.format('DD')+ ' '+ endMonth+ ' ' + startYear;168 } 169} else { 170 date = startDate.format('DD')+ ' '+ startMonth+ ' ' + startYear + '-' + endDate.format('DD')+ ' '+ endMonth+ ' ' + startYear; 171 172 if(localeAndDateFormat.locale == 'th')173 date = startDate.format('DD MMMM').toLowerCase()+ ' ' + startYear+'-' + endDate.format('DD MMMM').toLowerCase() + ' ' + endYear;174}175}176 177 } 178 return date;179 }...

Full Screen

Full Screen

daterangecustom.js

Source:daterangecustom.js Github

copy

Full Screen

1'use strict';23function customDaterangeFormat () {4 var sessionDateFinal = sessionDate.toUpperCase(); 5 var sepSign = "-";67 var dateFormat = 'YYYY M D';8 var showDateFormat = 'YYYY M D';910 if (sessionDateFinal.includes("/")){11 sepSign = '/';12 } else if (sessionDateFinal.includes(".")) {13 sepSign = '.';14 } else {15 sepSign = '-';16 }1718 var dateSep = dateFormat.replace(/ /g,sepSign);1920 switch(sessionDateFinal) {21 case 'YYYY' + sepSign + 'MM' + sepSign + 'DD':22 showDateFormat = 'YYYY M D';23 dateSep = showDateFormat.replace(/ /g,sepSign);24 break;25 case 'DD' + sepSign + 'MM' + sepSign + 'YYYY':26 showDateFormat = 'D M YYYY';27 dateSep = showDateFormat.replace(/ /g,sepSign);28 break;2930 case 'MM' + sepSign + 'DD' + sepSign+ 'YYYY':31 showDateFormat = 'M D YYYY';32 dateSep = showDateFormat.replace(/ /g,sepSign);33 break;34 case 'DD' + sepSign + 'M' + sepSign + 'YYYY':35 showDateFormat = 'D MMM YYYY';36 dateSep = showDateFormat.replace(/ /g,sepSign);37 break;3839 case 'YYYY' + sepSign + 'M' + sepSign + 'DD':40 showDateFormat = 'YYYY MMM D';41 dateSep = showDateFormat.replace(/ /g,sepSign);42 break;43 default:44 45 }4647 return {48 dateFormat: dateFormat, 49 showDateFormat: showDateFormat,50 sepSign:sepSign,51 dateSep:dateSep,52 }; 53}5455function dateRangeBtn (startDate, endDate,dt=null) {56 var df = dt;57 var customFormat = customDaterangeFormat();58 if(startDate == undefined || !startDate){59 var startDate = moment();60 startDate = moment(startDate, customFormat.showDateFormat);61 var endDate = moment();62 endDate = moment(endDate, customFormat.showDateFormat);63 } else {64 startDate = moment(startDate, customFormat.showDateFormat);65 endDate = moment(endDate, customFormat.showDateFormat);66 }6768 var init = moment();69 var initdate;70 if(dt == 1) {71 init = moment(0);72 initdate = moment(init, customFormat.dateFormat);73 var today = moment();74 today = moment(today, customFormat.dateFormat);7576 $('#daterange-btn').daterangepicker({77 ranges : {78 'Anytime' : [moment(0),moment()],79 'Today' : [moment(), moment()],80 'Yesterday' : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],81 'Last 7 Days' : [moment().subtract(6, 'days'), moment()],82 'Last 30 Days': [moment().subtract(29, 'days'), moment()],83 'This Month' : [moment().startOf('month'), moment().endOf('month')],84 'Last Month' : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]85 },86 "autoApply": true,87 "startDate": startDate,88 "endDate": endDate,89 "minDate": initdate,90 "drops": "auto",91 }, function(start, end) {92 93 var startDate = moment(start, customFormat.showDateFormat).format(customFormat.dateSep);94 $("#startDate").val(startDate);95 var endDate = moment(end, customFormat.showDateFormat).format(customFormat.dateSep);96 $("#endDate").val(endDate);97 initdate = moment(initdate, customFormat.showDateFormat).format(customFormat.dateSep);98 today = moment(today, customFormat.showDateFormat).format(customFormat.dateSep);99 if (startDate == 'undefined' || endDate == 'undefined') {100 $('#daterange-btn span').html('Pick a date range');101 } else if (startDate == '' || endDate == '' || (startDate === initdate && endDate === today )) {102 $('#daterange-btn span').html('Anytime');103 104 } else {105 startDate = moment(startDate, customFormat.showDateFormat).format(customFormat.dateSep);106 endDate = moment(endDate, customFormat.showDateFormat).format(customFormat.dateSep);107 $("#startDate").val(startDate);108 $("#endDate").val(endDate);109 $('#daterange-btn span').text(startDate + '-' + endDate );110 }111 });112 } else {113 initdate = moment(init, customFormat.dateFormat);114 $('#daterange-btn').daterangepicker({115 "autoApply": true,116 "alwaysShowCalendars": true,117 "startDate": startDate,118 "endDate": endDate,119 "minDate": initdate,120 "drops": "auto",121 }, function(start, end) {122 123 var startDate = moment(start, customFormat.showDateFormat).format(customFormat.dateSep);124 $("#startDate").val(startDate);125 var endDate = moment(end, customFormat.showDateFormat).format(customFormat.dateSep);126 $("#endDate").val(endDate);127 if(startDate=='' && endDate==''){128 $('#daterange-btn span').html('<i class="fa fa-calendar"></i> &nbsp;&nbsp; Pick a date range');129 } else {130 131 startDate = moment(startDate, customFormat.showDateFormat).format(customFormat.dateSep);132 endDate = moment(endDate, customFormat.showDateFormat).format(customFormat.dateSep);133 $("#startDate").val(startDate);134 $("#endDate").val(endDate);135 // $('#daterange-btn span').text(startDate + '-' + endDate );136 if(df == 'single') {137 price_calculation('', '', '');138 }139 }140 });141 }142}143144145function formDate (startDate, endDate) {146 var customFormat = customDaterangeFormat();147 var init = moment(0);148 var initdate;149 initdate = moment(init, customFormat.showDateFormat).format(customFormat.dateSep);150 var today = moment();151 today = moment(today, customFormat.showDateFormat).format(customFormat.dateSep);152153154155 if(startDate == undefined || !startDate){156 var startDate = moment();157 startDate = moment(startDate, customFormat.showDateFormat).format(customFormat.dateSep);158 var endDate = moment();159 endDate = moment(endDate, customFormat.showDateFormat).format(customFormat.dateSep);160 } else {161 startDate = moment(startDate, customFormat.showDateFormat).format(customFormat.dateSep);162 endDate = moment(endDate, customFormat.showDateFormat).format(customFormat.dateSep);163 }164 165 if (startDate == 'undefined' || endDate == 'undefined') {166 $('#daterange-btn span').html('Pick a date range');167 } else if (startDate == '' || endDate == '' || (startDate === initdate && endDate === today )) {168 $('#daterange-btn span').html('Anytime');169 170 } else {171 startDate = moment(startDate, customFormat.showDateFormat).format(customFormat.dateSep);172 endDate = moment(endDate, customFormat.showDateFormat).format(customFormat.dateSep);173 $("#startDate").val(startDate);174 $("#endDate").val(endDate);175 $('#daterange-btn span').text(startDate + '-' + endDate );176 } ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestTimeToBuyAndSellStock = require('./BestTimeToBuyAndSellStock');2let bts = new BestTimeToBuyAndSellStock();3let result = bts.endDate([7,1,5,3,6,4]);4class BestTimeToBuyAndSellStock {5 endDate(prices) {6 let maxProfit = 0;7 let minPrice = Number.MAX_SAFE_INTEGER;8 for (let i = 0; i < prices.length; i++) {9 if (prices[i] < minPrice) {10 minPrice = prices[i];11 } else if (prices[i] - minPrice > maxProfit) {12 maxProfit = prices[i] - minPrice;13 }14 }15 return maxProfit;16 }17}18module.exports = BestTimeToBuyAndSellStock;

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestBefore = require('./bestBefore.js');2var bestBefore1 = new bestBefore.BestBefore(2015, 3, 5);3var bestBefore2 = new bestBefore.BestBefore(2015, 3, 4);4console.log(bestBefore1.endDate());5console.log(bestBefore2.endDate());6exports.BestBefore = function (year, month, day) {7 this.year = year;8 this.month = month;9 this.day = day;10 this.endDate = function () {11 var endDate = new Date(this.year, this.month, this.day);12 endDate.setDate(endDate.getDate() + 1);13 return endDate;14 };15}16exports.BestBefore = function (year, month, day) {17 this.year = year;18 this.month = month;19 this.day = day;20 this.endDate = function () {21 var endDate = new Date(this.year, this.month, this.day);22 endDate.setDate(endDate.getDate() + 1);23 return endDate;24 };25};

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBefore = require('./BestBefore');2var bb = new BestBefore();3var endDate = bb.endDate();4console.log(endDate);5var BestBefore = function() {6 this.startDate = new Date();7 this.endDate = function() {8 var endDate = new Date();9 endDate.setDate(this.startDate.getDate() + 7);10 return endDate;11 };12};13module.exports = BestBefore;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBefore = require('./BestBefore.js');2var bb = new BestBefore();3bb.setEndDate('2016-01-01');4console.log(bb.getEndDate());5var BestBefore = require('./BestBefore.js');6var bb = new BestBefore();7bb.setEndDate('2016-01-01');8console.log(bb.getEndDate());9function BestBefore() {10 var endDate;11 this.setEndDate = function (date) {12 endDate = date;13 };14 this.getEndDate = function () {15 return endDate;16 };17 this.toString = function () {18 return 'BestBefore: ' + endDate;19 };20}21module.exports = BestBefore;22var BestBefore = require('./BestBefore.js');23var bb = new BestBefore();24bb.setEndDate('2016-01-01');25console.log(bb.getEndDate());26var BestBefore = require('./BestBefore.js');27var bb = new BestBefore();28bb.setEndDate('2016-01-01');29console.log(bb.getEndDate());30function BestBefore() {31 var endDate;32 this.setEndDate = function (date) {33 endDate = date;34 };35 this.getEndDate = function () {36 return endDate;37 };38 this.toString = function () {39 return 'BestBefore: ' + endDate;40 };41}42module.exports = BestBefore;43var BestBefore = require('./BestBefore.js');44var bb = new BestBefore();45bb.setEndDate('2016-01-01');46console.log(bb.getEndDate());47var BestBefore = require('./BestBefore.js');48var bb = new BestBefore();49bb.setEndDate('2016-01-01');50console.log(bb.getEndDate());51function BestBefore() {52 var endDate;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestTime = require('./bestTime');2var test4 = new BestTime();3test4.addTime(0, 0, 0, 0);4test4.addTime(0, 0, 0, 1);5test4.addTime(0, 0, 0, 2);6test4.addTime(0, 0, 0, 3);7test4.addTime(0, 0, 0, 4);8test4.addTime(0, 0, 0, 5);9test4.addTime(0, 0, 0, 6);10test4.addTime(0, 0, 0, 7);11test4.addTime(0, 0, 0, 8);12test4.addTime(0, 0, 0, 9);13console.log(test4.endDate());14var BestTime = require('./bestTime');15var test5 = new BestTime();16test5.addTime(0, 0, 0, 0);17test5.addTime(0, 0, 0, 1);18test5.addTime(0, 0, 0, 2);19test5.addTime(0, 0, 0, 3);20test5.addTime(0, 0, 0, 4);21test5.addTime(0, 0, 0, 5);22test5.addTime(0, 0, 0, 6);23test5.addTime(0, 0, 0, 7);24test5.addTime(0, 0, 0, 8);25test5.addTime(0, 0, 0, 9);26console.log(test5.bestTime());27var BestTime = require('./bestTime');28var test6 = new BestTime();29test6.addTime(0, 0, 0, 0);30test6.addTime(0, 0, 0, 1);31test6.addTime(0, 0, 0, 2);32test6.addTime(0, 0, 0, 3);33test6.addTime(0, 0,

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBefore = require('./BestBefore');2var myBB = new BestBefore(1, 1, 2000);3var end = myBB.endDate();4console.log('end date is ' + end);5var BestBefore = function(day, month, year) {6 this.day = day;7 this.month = month;8 this.year = year;9};10BestBefore.prototype.endDate = function() {11 var end = new Date(this.year, this.month, this.day);12 return end;13};14module.exports = BestBefore;15end date is Tue Feb 01 2000 00:00:00 GMT+0000 (UTC)

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBefore = require('./BestBefore');2var bestBefore = new BestBefore(2014, 7, 15);3console.log(bestBefore.endDate());4var BestBefore = require('./BestBefore');5var bestBefore = new BestBefore(2014, 7, 15);6console.log(bestBefore.daysLeft());7var BestBefore = require('./BestBefore');8var bestBefore = new BestBefore(2014, 7, 15);9console.log(bestBefore.isExpired());10var BestBefore = require('./BestBefore');11var bestBefore = new BestBefore(2014, 7, 15);12console.log(bestBefore.isExpired());13var BestBefore = require('./BestBefore');14var bestBefore = new BestBefore(2014, 7, 15);15console.log(bestBefore.isExpired());16var BestBefore = require('./BestBefore');17var bestBefore = new BestBefore(2014, 7, 15);18console.log(bestBefore.isExpired());19var BestBefore = require('./BestBefore');20var bestBefore = new BestBefore(2014, 7, 15);21console.log(bestBefore.isExpired());22var BestBefore = require('./BestBefore');23var bestBefore = new BestBefore(2014, 7, 15);24console.log(bestBefore.isExpired());25var BestBefore = require('./BestBefore');26var bestBefore = new BestBefore(2014, 7, 15);27console.log(bestBefore.isExpired());

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful