Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { status } from '../common/status.enum.js';
- /** The Task class holds all relevant data and behavior a task might have. */
- export class Task {
- #name;
- #dueDate;
- #status;
- constructor(initialName, initialDate){
- this.name = initialName;
- this.dueDate = initialDate;
- this.status = status.TODO;
- }
- get name(){
- return this.#name;
- }
- set name(value){
- if (!value || value.length <= 6 || value.length > 20) {
- throw new Error('Invalid person name!');
- }
- this.#name = value;
- }
- get dueDate(){
- return this.#dueDate;
- }
- set dueDate(value){
- if(value.valueOf() <= Date.now().valueOf()){
- throw new Error('Can\'t set due date to a date in the past!');
- }
- this.#dueDate = value;
- }
- get status(){
- return this.#status;
- }
- set status(value){
- this.#status = value;
- }
- /** Sets the task status to TODO. */
- reset() {
- this.status = status.TODO;
- }
- /** Sets the task status to IN_PROGRESS. */
- advance() {
- this.status = status.IN_PROGRESS;
- }
- /** Sets the task status to DONE. */
- complete() {
- this.status = status.DONE;
- }
- /** Transforms the task data into a formatted string */
- toString() {
- return `Name: ${this.name}\n` +
- `Status: ${this.status}\n` +
- `Due: ${this.dueDate.toLocaleDateString()} ${this.dueDate.toLocaleTimeString()}`;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment