mirror of
https://github.com/Lissy93/happy-app.git
synced 2021-05-12 19:52:18 +03:00
New helper functions in sharedmodule for timeline
This commit is contained in:
@@ -11,13 +11,29 @@ export class SharedModule {
|
||||
* @param historicalDate
|
||||
* @returns {number}
|
||||
*/
|
||||
getNumDaysFromDate(historicalDate){
|
||||
static getNumDaysFromDate(historicalDate){
|
||||
const day = 24*60*60*1000; // The number of milliseconds in one day
|
||||
const now = new Date().getTime(); // The time right now
|
||||
const then = new Date(historicalDate).getTime(); // The time comparing to
|
||||
return Math.round((now - then) / day ); // Find difference in milliseconds, then days
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the numeric value for string sentiment labels, specified in config
|
||||
* @param label
|
||||
* @returns {number}
|
||||
*/
|
||||
static convertLabelToValue(label){
|
||||
// TODO: These labels and values should be read from a config file
|
||||
switch(label) {
|
||||
case 'good': { return 1; }
|
||||
case 'average': { return 0; }
|
||||
case 'bad': { return -1; }
|
||||
default: { return 0; }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string array of each sentiment
|
||||
* @param rawData
|
||||
|
||||
Reference in New Issue
Block a user