-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from spira/feature/moment-date
Adding momentDate type. Updating userProfile.
- Loading branch information
Showing
9 changed files
with
177 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Moment overrides and additions | ||
|
||
declare module moment { | ||
interface Duration { | ||
toJSON():string; | ||
} | ||
|
||
interface Moment { | ||
getFullYear():number; | ||
getMonth():number; | ||
getDate():number; | ||
getTime():string; | ||
setHours(...args):Moment; | ||
} | ||
} | ||
|
||
|
||
(<any>moment).duration.fn.toString = function() { | ||
return (<any>moment)(this.hours() + ':' + this.minutes() + ':' + this.seconds(), 'HH:mm:ss').format('HH:mm:ss'); | ||
}; | ||
|
||
(<any>moment).duration.fn.toJSON = (<any>moment).duration.fn.toString; | ||
|
||
// Replace javascript Date object functions with moment ones. | ||
// This allows moment object to be used with date pickers. | ||
// See: DateLocaleProvider.prototype.$get:defaultFormatDate() in Angular Material source. | ||
// Refer to app.ts for further datepicker configuration. | ||
|
||
// These functions are required when the datepicker is opened | ||
(<any>moment).fn.getFullYear = (<any>moment).fn.year; | ||
|
||
(<any>moment).fn.getMonth = (<any>moment).fn.month; | ||
|
||
(<any>moment).fn.getDate = (<any>moment).fn.date; | ||
|
||
(<any>moment).fn.getTime = function() { | ||
return this.format('x'); // Returning time in milliseconds | ||
}; | ||
|
||
(<any>moment).fn.setHours = (<any>moment).fn.hours; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
describe('Moment', () => { | ||
|
||
describe('Moment overrides and additions', () => { | ||
|
||
it('should be able to get the full year', () => { | ||
|
||
expect(moment('1988-05-14').getFullYear()).to.equal(1988); | ||
|
||
}); | ||
|
||
it('should be able to get the month', () => { | ||
|
||
expect(moment('1988-05-14').getMonth()).to.equal(4); | ||
|
||
}); | ||
|
||
it('should be able to get the date', () => { | ||
|
||
expect(moment('1988-05-14').getDate()).to.equal(14); | ||
|
||
}); | ||
|
||
it('should be able to get the time', () => { | ||
|
||
expect(moment(111222333444555).getTime()).to.equal('111222333444555'); | ||
|
||
}); | ||
|
||
it('should be able to set hours', () => { | ||
|
||
expect(moment('1988-05-14 13:00:05').setHours(14).hours()).to.equal(14); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe('Moment duration overrides and additions', () => { | ||
|
||
it('should be able to format into a string', () => { | ||
|
||
expect(moment.duration(11111111).toString()).to.equal('03:05:11'); | ||
|
||
}); | ||
|
||
it('should be able to format to JSON', () => { | ||
|
||
expect(moment.duration(11111111).toJSON()).to.equal('03:05:11'); | ||
|
||
}); | ||
|
||
}); | ||
|
||
describe('MomentDate function', () => { | ||
|
||
it('should be able to create a new moment date object', () => { | ||
|
||
let mDate = momentDate('1988-05-14'); | ||
|
||
expect(mDate).to.be.instanceOf(moment); | ||
|
||
}); | ||
|
||
it('should have standard moment functions', () => { | ||
|
||
let mDate = momentDate('1988-05-14'); | ||
let m = moment('1988-05-14'); | ||
|
||
expect(mDate.hours()).to.equal(m.hours()); | ||
expect(mDate.isBefore('2010-10-21')).to.equal(m.isBefore('2010-10-21')); | ||
|
||
}); | ||
|
||
it('should have a different toString function', () => { | ||
|
||
let mDate = momentDate('1988-05-14'); | ||
let m = moment('1988-05-14'); | ||
|
||
expect(mDate.toISOString()).to.not.equal(m.toISOString()); | ||
expect(mDate.toISOString()).to.equal('1988-05-14'); | ||
expect(JSON.stringify(mDate)).to.equal('"1988-05-14"'); | ||
expect(mDate.toJSON()).to.equal('1988-05-14'); | ||
|
||
// Timezone is included in this output | ||
expect(mDate.toString()).to.equal('Sat May 14 1988'); | ||
expect(m.toString()).to.have.string('Sat May 14 1988 00:00:00'); | ||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
declare module moment { | ||
interface MomentDate extends Moment { | ||
} | ||
} | ||
|
||
function momentDate(...args) { | ||
var self = (<any>moment)(...args); | ||
|
||
(<any>self).__proto__ = momentDate.prototype; | ||
|
||
return self; | ||
} | ||
|
||
momentDate.prototype.__proto__ = (<any>moment).prototype; | ||
|
||
momentDate.prototype.toString = function () { | ||
return this.format('ddd MMM DD YYYY'); | ||
}; | ||
|
||
momentDate.prototype.toISOString = function () { | ||
return this.format('YYYY-MM-DD'); | ||
}; | ||
|
||
momentDate.prototype.toJSON = function () { | ||
return this.format('YYYY-MM-DD'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters