{"id":21063511,"url":"https://github.com/bosnaufal/counting-day","last_synced_at":"2025-05-16T02:31:53.574Z","repository":{"id":57209852,"uuid":"99641052","full_name":"BosNaufal/counting-day","owner":"BosNaufal","description":"Mini library to count your day","archived":false,"fork":false,"pushed_at":"2017-11-14T10:49:27.000Z","size":143,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T15:59:11.270Z","etag":null,"topics":["date","date-formatting","datepicker","dates","datetime"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BosNaufal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-08T02:29:38.000Z","updated_at":"2018-09-04T01:31:55.000Z","dependencies_parsed_at":"2022-08-29T11:50:31.071Z","dependency_job_id":null,"html_url":"https://github.com/BosNaufal/counting-day","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BosNaufal%2Fcounting-day","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BosNaufal%2Fcounting-day/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BosNaufal%2Fcounting-day/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BosNaufal%2Fcounting-day/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BosNaufal","download_url":"https://codeload.github.com/BosNaufal/counting-day/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254455944,"owners_count":22074064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date","date-formatting","datepicker","dates","datetime"],"created_at":"2024-11-19T17:45:47.206Z","updated_at":"2025-05-16T02:31:48.564Z","avatar_url":"https://github.com/BosNaufal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Counting Day\n\nMini library to count your day. sometime we just need to add some day to define a date like *today, yesterday, last week, last 7 days, last 30 days, etc*. But you feel too expensive to include a popular library with a big size of file. Now, you can do it with **5kB** library. So, let's count your day!\n\n## Install\nYou can import [counting-day.min.js](./dist/counting-day.min.js) to your js file like [this](./examples/index.js) and process it with your preprocessor.\n\nYou can install it via NPM\n```bash\nnpm install counting-day\n```\n\n\n## Import Module\n```javascript\nimport CountingDay from 'counting-day'\n// Or\nvar CountingDay = require('counting-day');\n```\n\n## Usage\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\n\nlet info = counting.addDay(31).get()\nconsole.log(info);\n/** Will return object with full date info\n{\n  day: index of day (number: 0 - 6),\n  date: the date (number: 1 - 31),\n  month: index of month (number: 1 - 12),\n  maxDay: the max day of the month (number: 28 - 31),\n  year: current year,\n}\n*/\n\n// will mutate the state of the instance\nlet last7Days = couting.addDay(-7).get() // date: 25, month: 12, year: 2016\n\n// will directly return the object wihtout get() method and doesn't mutate the instance state\nlet last30Days = counting.addDay(-7, 1, 2, 2017) // date: 25, month: 1, year: 2017\n\n// Will mutate instance state\nlet addMonth = counting.addMonth(2).get() // date: 25, month: 2, year: 2017\n\n// Will not mutate the instance state since it has a initial date manually\nlet addMonthWithManualInit = counting.addMonth(2, 1, 2, 2017).get() // date: 1, month: 4, year: 2017\n\n// Will mutate instance state\nlet addYear = counting.addYear(2).get() // date: 25, month: 2, year: 2020\n\n// Will not mutate the instance state\nlet addYearWithInit = counting.addYear(2, 1, 1, 2017) // date: 1, month: 1, year: 2017\n\n// Produce SQL format\nlet SQLFormat = counting.getSQLDate() // 2020-02-25\n\n// return Date instance with current state as its arguments\nlet DateInstance = counting.getDate()\n\n// then() function will return a new instance of CountingDay, so it will never mutate the last `counting` instance\nlet differentCounting = addYearWithInit.then()\n  .addDay(5)\n  .addMonth(1)\n  .addYear(10)\n  .getSQLDate()\n// Will Return 2027-02-06\n\nconsole.log(counting === differentCounting); // false\n```\n\n\n## Methods\n### `Constructor` (Object: { date, month, year }) =\u003e (Instance)\nFirst of all we need to init our Constructor.\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\nconsole.log(counting.get());\n```\n\n___\n\n\n### `fromDate` (Date: date) =\u003e (Instance)\nAnother way to create a new instance from the `new Date()` Object\n```javascript\nconst now = new Date()\nconst couting = CountingDay.fromDate(now)\nconsole.log(counting.get());\n```\n\n___\n\n\n### `isLeap` (Number: year) =\u003e (Boolean)\nIt cares about the leap.\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\nconsole.log(counting.isLeap()); // false\ncounting.addYear(3) // year: 2020\nconsole.log(counting.isLeap()); // true\n\nconst withManualInit = counting.isLeap(2040)\nconsole.log(withManualInit); // true\n```\n\n___\n\n\n### `maxDayCount` (Number: month, Number: year) =\u003e (Number)\nIt can also count the max day of the month.\n```javascript\nconst couting = new CountingDay({ date: 1, month: 2, year: 2017 })\nconst maxDayOfFebruary = counting.maxDayCount()\nconsole.log(maxDayOfFebruary); // 28\n\nconst anotherFebruary = counting.maxDayCount(2, 2020)\nconsole.log(anotherFebruary); // 29\n```\n\n___\n\n\n### `addDay` (Number: count, [Number: date, [Number: month, [Number: year]]]) =\u003e (Object)\nIt can add your day with positive or negative value of `count` argument. Other arguments next to `count` is custom initial and it is optional, you can pass all of them or one of them. When you pass the custom initial arguments you will get a new CountingDay in the `then()` function.\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\n// Will mutate the state\ncounting.addDay(6)\nconsole.log(couting.get()); // date: 7, month: 1, year: 2017\n\n// Will not mutate the state\nconst customInit = counting.addDay(-2, 5) // start from date: 5\nconsole.log(customInit); // date: 3, month: 1, year: 2017\n\nconst anotherCustomInit = customInit.then().addDay(-5, 15, 2, 2020)\nconsole.log(anotherCustomInit) // date: 10, month: 2, year: 2020\n```\n\n___\n\n\n### `addMonth` (Number: count, [Number: date, [Number: month, [Number: year]]]) =\u003e (Object)\nJust like `addDay` method, but it will add your month instead your date.\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\n// Will mutate the state\ncounting.addMonth(6)\nconsole.log(couting.get()); // date: 1, month: 7, year: 2017\n\n// Will not mutate the state\nconst customInit = counting.addMonth(-6, 1, 12) // start from date: 1, month: 12\nconsole.log(customInit); // date: 1, month: 6, year: 2017\n\nconst anotherCustomInit = customInit.then().addMonth(12, 1, 1, 2020)\nconsole.log(anotherCustomInit) // date: 1, month: 1, year: 2021\n```\n\n___\n\n\n### `addYear` (Number: count, [Number: date, [Number: month, [Number: year]]]) =\u003e (Object)\nHas some behaviout with `addDay` and `addMonth` method. It will add your Year.\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\n// Will mutate the state\ncounting.addYear(6)\nconsole.log(couting.get()); // date: 1, month: 1, year: 2023\n\n// Will not mutate the state\nconst customInit = counting.addYear(-10, 1, 2, 2000) // start from date: 1, month: 2, year: 2000\nconsole.log(customInit); // date: 1, month: 2, year: 1990\n\nconst anotherCustomInit = customInit.then().addYear(12, 1, 1, 2020)\nconsole.log(anotherCustomInit) // date: 1, month: 1, year: 2022\n```\n\n___\n\n\n### `then` () =\u003e (Object)\n`then()` method is not a instance method, it is a function returned by `addDay`, `addMonth`, or `addYear` method that run with custom initial argument.\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\n\n// Will not mutate the state\nconst customInit = counting.addMonth(6, 1, 2) // start from date: 1, month: 2\nconsole.log(customInit); // date: 1, month: 8, year: 2017\n\nconst anotherCustomInit = customInit.then().addMonth(12, 1, 1, 2020)\nconsole.log(anotherCustomInit) // date: 1, month: 1, year: 2021\n```\n\n___\n\n\n### `get` () =\u003e (Object)\nWill return current state instance as an Object.\n```javascript\nconst now = new Date()\nconst couting = CountingDay.fromDate(now)\nconsole.log(counting.get());\n/*\n  =\u003e {\n    day: index of day (number: 0 - 6),\n    date: the date (number: 1 - 31),\n    month: index of month (number: 1 - 12),\n    maxDay: the max day of the month (number: 28 - 31),\n    year: current year,\n  }\n*/\n```\n\n___\n\n\n### `getDate` () =\u003e (Object)\nThis method will create Date instance from the current state\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\ncounting.getDate() // =\u003e new Date(2017, 1, 1)\n```\n\n___\n\n\n### `getSQLDate` () =\u003e (Object)\nThis method will return SQL date format from current state\n```javascript\nconst couting = new CountingDay({ date: 1, month: 1, year: 2017 })\ncounting.getSQLDate() // =\u003e 2017-01-01\n```\n\n\n## Thank You for Making this useful~\n\n## Let's talk about some projects with me\nJust Contact Me At:\n- Email: [bosnaufalemail@gmail.com](mailto:bosnaufalemail@gmail.com)\n- Skype Id: bosnaufal254\n- twitter: [@BosNaufal](https://twitter.com/BosNaufal)\n\n## License\n[MIT](http://opensource.org/licenses/MIT)\nCopyright (c) 2016 - forever Naufal Rabbani\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbosnaufal%2Fcounting-day","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbosnaufal%2Fcounting-day","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbosnaufal%2Fcounting-day/lists"}