it('should update the date to one month ago', () => {
     datepicker.open();
     let oneMonthAgo = moment().subtract(1, 'months').format(isoFormat);
     datepicker.date = oneMonthAgo;
     expect(datepicker.date).to.eventually.eql(oneMonthAgo);
 });
Example #2
0
 it('should initialize properly', () => {
     expect(moment().isSame(dp.now, 'day')).toBeTruthy();
     expect(dp._baseMonth).toEqual(moment().month());
     expect(dp.hideComponent).toBe(true);
 });
Example #3
0
 transform(value: string, formatFrom: string, formatTo: string = 'DD.MM.YYYY'): string {
   return moment(value, formatFrom).format(formatTo);
 }
 function getMoment(culture: string, value: any, format: string | undefined) {
     return culture ? localField(moment(value, format))(culture) : moment(value, format);
 }
 m.smartNow = function () { return moment(); };
Example #6
0
    transform(value: number, args: string[]) : any {
		var date = moment(value).locale('de').fromNow()+' : '+moment(value).locale('de').format('dddd, Do MMMM ');
        return date;
    }
Example #7
0
 function format(value: string | Date, format='YYYY-MM-DD HH:mm'): string {
   return moment(value).format(format);
 }
Example #8
0
 public async getResults(id: number, dateFrom?: Date, dateTo?: Date) {
     return await this.httpClient.get<ICheckResults>("/api/results/" + id.toString()
         + (typeof dateFrom !== "undefined" ? "/" + moment(dateFrom).format("YYYY-MM-DD") : "")
         + (typeof dateTo !== "undefined" ? "/" + moment(dateTo).format("YYYY-MM-DD") : "")).pipe(first()).toPromise();
 }
                return getConnection().then(connection => {
                    ApplicationModel.setConnection(connection);
                    ApplicationBasicinfoModel.setConnection(connection);

                    let beforeId, afterId;
                    return new ApplicationModel({
                        agencyCode: 'agencyCode',
                        cscId: 'cscId',
                        applyType: 'applyType',
                        type: 'type',
                        submitType: 'st',
                        dispacth: 'dispacth',
                        dispacthProject: 'dp',
                        projectAttr: 'pa',
                        projectType: 'pt',
                        projectName: 'pn',
                        candidateType: 'candidateType',
                        remark1: 'remark1',
                        remark2: 'remark2',
                        remark3: 'remark3',
                        remark4: 'remark4',
                        status: 'status',
                        statusUpdateAt: m(),
                        createBy: 'createBy',
                        createAt: m(),
                        updateBy: 'updateBy',
                        updateAt: m()
                    }).save().then(_application => {
                        let id = _application.id;
                        beforeId = _application.id;
                        return new ApplicationBasicinfoModel({
                            id,
                            firstname: 'firstname',
                            lastname: 'lastname',
                            fullname: 'f l',
                            chineseName: 'chineseName',
                            gender: 'gender',
                            birthday: m(),
                            maritalStatus: 'maritalStatus',
                            nationality: 'n',
                            passportCode: 'passportCode',
                            nativeLanguage: 'nl',
                            religion: 'religion',
                            birthCountry: 'birthCountry',
                            birthCity: 'birthCity',
                            permanentTel: 'permanentTel',
                            permanentFax: 'permanentFax',
                            permanentEmail: 'permanentEmail',
                            permanentAddress: 'permanentAddress',
                            presentTel: 'presentTel',
                            presentFax: 'presentFax',
                            presentEmail: 'presentEmail',
                            presentAddress: 'presentAddress',
                            passportDeadline: m(),
                        }).save();

                        // _application.cscId = 'CSCiD';
                        // return _application.save();
                    }).then(_basicinfo => {
                        _basicinfo.gender = 'GENdER';
                        return _basicinfo.save();
                    }).then(_basicinfo => {
                        afterId = _basicinfo.id;
                        assert(_basicinfo.gender, 'GENdER');
                        assert.equal(beforeId, afterId);
                        return connection;
                    });
                }).then(connection => connection.release());
 @Transform(value => moment(value), { since: 1, until: 2 })
Example #11
0
 public transform(timestamp: number): string {
     if (!timestamp) { return 'unknown'; }
     return moment(timestamp).fromNow();
 }
 @Transform(value => moment(value), { toClassOnly: true })
Example #13
0
 setExpiresIn(seconds: number) {
     this.expiresAt = moment().add(seconds, "seconds").toDate();
 }
    return () => {
        let selectedYear: string;
        let selectedMonth: string;
        let selectedDay: string;

        let datepicker: component.rxDatePicker;
        let isoFormat = 'YYYY-MM-DD';
        let formatYear = 'YYYY';
        let formatMonth = 'MM';
        let formatDay = 'DD';

        let currentMonthYear: string;
        let previousMonth: moment.Moment;
        let nextMonth: moment.Moment;

        if (options.selectedDate) {
            let m = moment(options.selectedDate);
            selectedYear = m.format(formatYear);
            selectedMonth = m.format(formatMonth);
            selectedDay = m.format(formatDay);
        } else {
            let m = moment();
            selectedYear = m.format(formatYear);
            selectedMonth = m.format(formatMonth);
            // there is no selected day in a blank datepicker
        }

        before(() => {
            datepicker = options.instance;
        });

        it(`should ${options.present ? '' : 'not '}be present`, () => {
            expect(datepicker.isPresent()).to.eventually.eql(options.present);
        });

        if (!options.present) {
            return;
        }

        it(`should ${options.displayed ? '' : 'not '}be displayed`, () => {
            expect(datepicker.isDisplayed()).to.eventually.eql(options.displayed);
        });

        if (!options.displayed) {
            return;
        }

        if (options.selectedDate !== null) {
            it(`should have '${options.selectedDate}' as the current selected date`, () => {
                expect(datepicker.date).to.eventually.eql(options.selectedDate);
            });
        }

        it(`should ${options.valid ? '' : 'not '}be valid`, () => {
            expect(datepicker.isValid()).to.eventually.eql(options.valid);
        });

        it(`should ${options.enabled ? '' : 'not '}be enabled`, () => {
            expect(datepicker.isEnabled()).to.eventually.eql(options.enabled);
        });

        it(`should ${options.open ? '' : 'not '}already have the calendar open`, () => {
            expect(datepicker.isOpen()).to.eventually.eql(options.open);
        });

        if (!options.enabled) {
            return;
        }

        it(`should ${options.open ? 'close ' : 'open '}the calendar`, () => {
            options.open ? datepicker.close() : datepicker.open();
            expect(datepicker.isOpen()).to.eventually.eql(!options.open);
        });

        it('should return the calendar back to its original state', () => {
            options.open ? datepicker.open() : datepicker.close();
            expect(datepicker.isOpen()).to.eventually.eql(options.open);
        });

        it(`should have '${selectedMonth}' as the current selected month in the dropdown`, () => {
            datepicker.open();
            expect(datepicker.month).to.eventually.eql(selectedMonth);
        });

        it(`should have '${selectedYear}' as the current selected year in the dropdown`, () => {
            expect(datepicker.year).to.eventually.eql(selectedYear);
        });

        it('should have some days that are in the current month', () => {
            expect(datepicker.currentMonthDays.count()).to.eventually.be.above(0);
        });

        it('should have some days that are out of the current month', () => {
            expect(datepicker.$$('.day.outOfMonth').count()).to.eventually.be.above(0);
        });

        it('should not select a date that is out of month', () => {
            (datepicker.date as Promise<string>).then(currentDate => {
                datepicker.$$('.day.outOfMonth span').each(invalidDay => {
                    invalidDay.click();
                    expect(datepicker.date).to.eventually.eql(currentDate);
                });
            });
        });

        it('should navigate back one month', () => {
            (datepicker.year as Promise<string>).then(year => {
                (datepicker.month as Promise<string>).then(month => {
                    datepicker.previousMonth();
                    currentMonthYear = `${year}-${month}`;
                    previousMonth = moment(currentMonthYear, 'YYYY-MM').subtract(1, 'month');
                    expect(datepicker.month).to.eventually.eql(previousMonth.format(formatMonth));
                });
            });
        });

        it('should navigate forward two months', () => {
            datepicker.nextMonth();
            datepicker.nextMonth();
            nextMonth = moment(currentMonthYear).add(1, 'month');
            expect(datepicker.month).to.eventually.eql(nextMonth.format(formatMonth));
        });

        it('should reopen the calendar and have the month unchanged', () => {
            datepicker.close();
            datepicker.open();
            expect(datepicker.month).to.eventually.eql(nextMonth.format(formatMonth));
            expect(datepicker.year).to.eventually.eql(nextMonth.format(formatYear));
            datepicker.previousMonth();
        });

        if (options.selectedDate !== null) {
            it('should update the date to one month from now', () => {
                datepicker.open();
                datepicker.date = nextMonth.format(isoFormat);
                expect(datepicker.date).to.eventually.eql(nextMonth.format(isoFormat));
            });

            it('should update the date to one month ago', () => {
                datepicker.open();
                let oneMonthAgo = moment().subtract(1, 'months').format(isoFormat);
                datepicker.date = oneMonthAgo;
                expect(datepicker.date).to.eventually.eql(oneMonthAgo);
            });

            it('should return the date back to its original date', () => {
                datepicker.open();
                datepicker.date = options.selectedDate;
                expect(datepicker.date).to.eventually.eql(options.selectedDate);
            });
        }

        describe('today\'s date', () => {
            let today: string;
            let currentDate: string;

            before(() => {
                today = moment().format(isoFormat);
                datepicker.open();
                (datepicker.date as Promise<string>).then(date => {
                    currentDate = date;
                    datepicker.date = today;
                });
            });

            it('should be highlighted with a special class', () => {
                datepicker.open();
                expect(datepicker.getDateToday()).to.eventually.eql(today);
            });

            it('should highlight the currently selected date with a special class', () => {
                datepicker.open();
                expect(datepicker.getDateSelected()).to.eventually.eql(today);
            });

            it('should update the date to the first of the month', () => {
                let firstOfMonth = moment().startOf('month').format(isoFormat);
                datepicker.date = firstOfMonth;
                datepicker.open();
                expect(datepicker.date).to.eventually.eql(firstOfMonth);
                expect(datepicker.getDateSelected()).to.eventually.eql(firstOfMonth);
            });

            after(() => {
                datepicker.open();
                datepicker.date = currentDate;
            });

        });

        after(() => {
            options.open ? datepicker.open() : datepicker.close();
        });

    };
Example #15
0
 onDocument: async (doc) => ranInFuture = moment() >= future,
                return getConnection().then(connection => {
                    ApplicationBasicinfoModel.setConnection(connection);
                    ApplicationModel.setConnection(connection);

                    let id = UUID.create();
                    let application = new ApplicationModel({
                        id,
                        agencyCode: 'agencyCode',
                        cscId: 'cscId',
                        applyType: 'applyType',
                        type: 'type',
                        submitType: 'st',
                        dispacth: 'dispacth',
                        dispacthProject: 'dp',
                        projectAttr: 'pa',
                        projectType: 'pt',
                        projectName: 'pn',
                        candidateType: 'candidateType',
                        remark1: 'remark1',
                        remark2: 'remark2',
                        remark3: 'remark3',
                        remark4: 'remark4',
                        status: 'status',
                        statusUpdateAt: m(),
                        createBy: 'createBy',
                        createAt: m(),
                        updateBy: 'updateBy',
                        updateAt: m()
                    });
                    let basicinfo1 = new ApplicationBasicinfoModel({
                        id,
                        firstname: 'firstname',
                        lastname: 'lastname',
                        fullname: 'f l',
                        chineseName: 'chineseName',
                        gender: 'gender',
                        birthday: m(),
                        maritalStatus: 'maritalStatus',
                        nationality: 'n',
                        passportCode: 'passportCode',
                        nativeLanguage: 'nl',
                        religion: 'religion',
                        birthCountry: 'birthCountry',
                        birthCity: 'birthCity',
                        permanentTel: 'permanentTel',
                        permanentFax: 'permanentFax',
                        permanentEmail: 'permanentEmail',
                        permanentAddress: 'permanentAddress',
                        presentTel: 'presentTel',
                        presentFax: 'presentFax',
                        presentEmail: 'presentEmail',
                        presentAddress: 'presentAddress',
                        passportDeadline: m(),
                    });
                    return application.save().then(application => {
                        return basicinfo1.save();
                    }).then(() => {
                        return ApplicationBasicinfoModel.findById(id)
                    }).then(basicinfo2 => {
                        assert(basicinfo1.isEquals(basicinfo2), '查询出的结果需要与存入的相同');
                        return connection
                    });
                }).then(connection => connection.release());
Example #17
0
 onDocument: async (doc) => repeated = moment(),
 esiidIdList.forEach(s => {
     let selectedStartDt: string = moment((esiidIdList.pop().selectedStartDate)).format("MM/DD/YYYY");
     if(CommonUtil.isNotBlank(esiidIdList.pop().selectedStartDate) && (moment(today).isSame(selectedStartDt)) && dateUtil.isNearTo5PM("Verify")) {
       isSameDayNearto5pmflag = true;
     }
 });
Example #19
0
 function formatHuman(value: string | Date): string {
   let time = moment(value).fromNow();
   time = time === 'a few seconds ago' ? 'seconds ago' : time;
   return time;
 }
export function ChatExampleData(store: Redux.Store<AppState>) {

  // set the current User
  store.dispatch(UserActions.setCurrentUser(me));

  // create a new thread and add messages
  store.dispatch(ThreadActions.addThread(tLadycap));
  store.dispatch(ThreadActions.addMessage(tLadycap, {
    author: me,
    sentAt: moment().subtract(45, 'minutes').toDate(),
    text: 'Yet let me weep for such a feeling loss.'
  }));
  store.dispatch(ThreadActions.addMessage(tLadycap, {
    author: ladycap,
    sentAt: moment().subtract(20, 'minutes').toDate(),
    text: 'So shall you feel the loss, but not the friend which you weep for.'
  }));

  // create a few more threads
  store.dispatch(ThreadActions.addThread(tEcho));
  store.dispatch(ThreadActions.addMessage(tEcho, {
    author: echo,
    sentAt: moment().subtract(1, 'minutes').toDate(),
    text: 'I\'ll echo whatever you send me'
  }));

  store.dispatch(ThreadActions.addThread(tRev));
  store.dispatch(ThreadActions.addMessage(tRev, {
    author: rev,
    sentAt: moment().subtract(3, 'minutes').toDate(),
    text: 'I\'ll reverse whatever you send me'
  }));

  store.dispatch(ThreadActions.addThread(tWait));
  store.dispatch(ThreadActions.addMessage(tWait, {
    author: wait,
    sentAt: moment().subtract(4, 'minutes').toDate(),
    text: `I\'ll wait however many seconds you send to me before responding.` +
      ` Try sending '3'`
  }));

  // select the first thread
  store.dispatch(ThreadActions.selectThread(tLadycap));

  // Now we set up the "bots". We do this by watching for new messages and
  // depending on which thread the message was sent to, the bot will respond
  // in kind.

  const handledMessages = {};

  store.subscribe( () => {
    getAllMessages(store.getState())
      // bots only respond to messages sent by the user, so
      // only keep messages sent by the current user
      .filter(message => message.author.id === me.id)
      .map(message => {

        // This is a bit of a hack and we're stretching the limits of a faux
        // chat app. Every time there is a new message, we only want to keep the
        // new ones. This is a case where some sort of queue would be a better
        // model
        if (handledMessages.hasOwnProperty(message.id)) {
          return;
        }
        handledMessages[message.id] = true;

        switch (message.thread.id) {
          case tEcho.id:
            // echo back the same message to the user
            store.dispatch(ThreadActions.addMessage(tEcho, {
              author: echo,
              text: message.text
            }));

            break;
          case tRev.id:
            // echo back the message reveresed to the user
            store.dispatch(ThreadActions.addMessage(tRev, {
              author: rev,
              text: message.text.split('').reverse().join('')
            }));

            break;
          case tWait.id:
            let waitTime: number = parseInt(message.text, 10);
            let reply: string;

            if (isNaN(waitTime)) {
              waitTime = 0;
              reply = `I didn\'t understand ${message}. Try sending me a number`;
            } else {
              reply = `I waited ${waitTime} seconds to send you this.`;
            }

            setTimeout(
              () => {
                store.dispatch(ThreadActions.addMessage(tWait, {
                  author: wait,
                  text: reply
                }));
              },
              waitTime * 1000);

            break;
          default:
            break;
        }
      });
  });
}
].map((d) => moment(d, ' "YYYY-MM-DD"'));
Example #22
0
target.__typeCasts.set(propertyKey, (value: string, reference:BaseModel) => moment(value));
 function endOfCentury(date: Date) {
     return moment(date).add(100, 'year').add(-1, 'millisecond').toDate();
 }
export let formatTime = (input: string) => {
  let iso = new Date(input).toISOString();
  return moment(iso).format("HH:mm");
};
Example #25
0
    it('should check for sanity of chosen dates with sanitize on and off', () => {
        const day1 = moment([2016, 5, 1]);
        const day2 = moment([2016, 5, 2]);
        const day3 = moment([2016, 5, 3]);
        const day5 = moment([2016, 5, 5]);
        const day10 = moment([2016, 5, 10]);

        // bulk set date properties
        const dateReset = (beginDate, endDate, beginRange, endRange, maxRange = 5) => {
            dp._beginDate = beginDate;
            dp._endDate = endDate;
            dp._beginRange = beginRange;
            dp._endRange = endRange;
            dp._maxRange = maxRange;
        };

        // use to check date values
        const dateCheck = (beginDate, endDate) => {
            expect(dp._beginDate).toBe(beginDate);
            expect(dp._endDate).toBe(endDate);
        };

        // norml day within range
        dateReset(day1, day3, undefined, undefined, 5);
        expect(dp.sanityCheck(false)).toBeTruthy();
        dateCheck(day1, day3);
        expect(dp.sanityCheck(true)).toBeTruthy();
        dateCheck(day1, day3);

        // normal day out of max range
        dateReset(day1, day5, undefined, undefined, 2);
        expect(dp.sanityCheck(false)).toBeFalsy();
        dateCheck(day1, day5);
        expect(dp.sanityCheck(true)).toBeFalsy();
        dateCheck(day5, undefined);

        // within maxrange, out of bounds
        dateReset(day1, day5, undefined, day3, 10);
        expect(dp.sanityCheck(false)).toBeFalsy();
        dateCheck(day1, day5);
        expect(dp.sanityCheck(true)).toBeFalsy();
        dateCheck(day1, undefined);

        // within maxrange, out of bounds
        dateReset(day1, day5, day2, day10, 10);
        expect(dp.sanityCheck(false)).toBeFalsy();
        dateCheck(day1, day5);
        expect(dp.sanityCheck(true)).toBeFalsy();
        dateCheck(undefined, undefined);

        // within maxrange & range, end date before start date
        dateReset(day5, day2, day1, day10, 10);
        expect(dp.sanityCheck(false)).toBeFalsy();
        dateCheck(day5, day2);
        expect(dp.sanityCheck(true)).toBeFalsy();
        dateCheck(day2, undefined);
        
        // valid startDate, but endDate out of bound
        dateReset(day2, day10, day1, day5, 3);
        expect(dp.sanityCheck(false)).toBeFalsy();
        dateCheck(day2, day10);
        expect(dp.sanityCheck(true)).toBeFalsy();
        dateCheck(day2, undefined);

        // valid startdate, enddate out of range
        dateReset(day3, day1, day2, day5, 3);
        expect(dp.sanityCheck(false)).toBeFalsy();
        dateCheck(day3, day1);
        expect(dp.sanityCheck(true)).toBeFalsy();
        dateCheck(day3, undefined);
    });
export let formatDate = (input: string) => {
  let iso = new Date(input).toISOString();
  return moment(iso).format("YYYY-MM-DD");
};
Example #27
0
    it('should generate correct calendar with between ', () => {
        dp._beginDate = moment([2016, 10, 1]);
        dp._endDate = moment([2016, 10, 3]);

    });
Example #28
0
 setTimeFormat(format:string) {
   const formatedTime = moment(this.relativeTime).format(format);//this.relativeTime
   return new Process(Object.assign({}, this, { relativeTime: formatedTime }));
 }
Example #29
0
 transform(date: string): string {
   var date = date;
   return moment(date, "YYYYMMDD").startOf('day').fromNow();
 }
 it('should navigate forward two months', () => {
     datepicker.nextMonth();
     datepicker.nextMonth();
     nextMonth = moment(currentMonthYear).add(1, 'month');
     expect(datepicker.month).to.eventually.eql(nextMonth.format(formatMonth));
 });