https://github.com/kmdtmyk/ruby-date.js
Date class for JavaScript that can be used same as Ruby's Date
https://github.com/kmdtmyk/ruby-date.js
date javascript ruby
Last synced: 5 months ago
JSON representation
Date class for JavaScript that can be used same as Ruby's Date
- Host: GitHub
- URL: https://github.com/kmdtmyk/ruby-date.js
- Owner: kmdtmyk
- License: mit
- Created: 2021-03-18T03:03:09.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-19T05:33:17.000Z (11 months ago)
- Last Synced: 2025-11-22T14:20:53.913Z (8 months ago)
- Topics: date, javascript, ruby
- Language: TypeScript
- Homepage:
- Size: 456 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/kmdtmyk/ruby-date.js/actions)
[](https://github.com/kmdtmyk/ruby-date.js/actions)
# RubyDate
Date class that can be used same as Ruby's Date.
## Installation
```
npm install @kmdtmyk/ruby-date
```
## Usage
```javascript
import RubyDate from '@kmdtmyk/ruby-date'
const date = new RubyDate(2021, 3, 15) // => 2021-03-15
date.day() // => 15
date.month() // => 3
date.year() // => 2021
date.wday() // => 1 (0-6, Sunday is 0)
date.beginningOfMonth() // => 2021-03-01
date.endOfMonth() // => 2021-03-31
date.beginningOfYear() // => 2021-01-01
date.endOfYear() // => 2021-12-31
date.nextDay() // => 2021-03-16
date.nextDay(3) // => 2021-03-18
date.nextMonth() // => 2021-04-15
date.nextMonth(3) // => 2021-06-15
date.nextYear() // => 2022-03-15
date.nextYear(3) // => 2024-03-15
date.strftime('%Y/%m/%d') // => "2021/03/15"
/*
[Support format]
%m - zero-padded month (01..12)
%d - zero-padded day (01..31)
%Y - Year with century (can be negative, 4 digits at least)
%y - year % 100 (00..99)
*/
date.toDate() // => return JavaScript standard build-in Date object
date.toString() // => "2021-03-15"
```
```javascript
RubyDate.parse('2021/03/15') // => 2021-03-15
RubyDate.today()
```
## npm
```bash
npm version [major | minor | patch]
git push
git push --tags
```
## License
MIT