| 23 | * @param data Series or Array of date strings |
| 24 | */ |
| 25 | export default class TimeSeries implements DateTime { |
| 26 | private $dateObjectArray: Array<Date> |
| 27 | |
| 28 | constructor(data: Series | ArrayType1D) { |
| 29 | if (data instanceof Series) { |
| 30 | this.$dateObjectArray = this.processData(data.values as ArrayType1D) |
| 31 | } else { |
| 32 | this.$dateObjectArray = this.processData(data) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Processed the data values into internal structure for easy access |
| 38 | * @param dateArray An array of date strings |
| 39 | */ |
| 40 | private processData(dateArray: ArrayType1D): Array<Date> { |
| 41 | const values = dateArray.map(dateString => new Date(`${dateString}`)) |
| 42 | return values |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the month, in local time. |
| 47 | * @example |
| 48 | * ``` |
| 49 | * import { Series } from "danfojs-node" |
| 50 | * const data = [ |
| 51 | * "2019-01-01", |
| 52 | * "2019-02-01", |
| 53 | * "2019-03-01", |
| 54 | * "2019-04-01", |
| 55 | * ] |
| 56 | * const df = new Series(data) |
| 57 | * const dfNew = df.dt.month() |
| 58 | * console.log(dfNew.values) |
| 59 | * // [1, 2, 3, 4] |
| 60 | * ``` |
| 61 | */ |
| 62 | month(): Series { |
| 63 | const newValues = this.$dateObjectArray.map(date => date.getMonth()) |
| 64 | return new Series(newValues); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the day of the week, in local time |
| 69 | * @example |
| 70 | * ``` |
| 71 | * import { Series } from "danfojs-node" |
| 72 | * const data = [ |
| 73 | * "2019-01-01", |
| 74 | * "2019-02-01", |
| 75 | * "2019-03-01", |
| 76 | * "2019-04-01", |
| 77 | * ] |
| 78 | * const df = new Series(data) |
| 79 | * const dayOfWeek = df.dt.dayOfWeek() |
| 80 | * console.log(dayOfWeek.values) |
| 81 | * ``` |
| 82 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected