Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed toBikramSambat to fromAD #41

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const isAfter = date1.isAfter(date2); // true
Convert dates between the Bikram Sambat and Gregorian calendars:

```javascript
const gregorianDate = date1.toGregorian(); // JavaScript Date object
const bsDate = BikramSambat.toBikramSambat(gregorianDate);
const gregorianDate = date1.toAD(); // JavaScript Date object
const bsDate = BikramSambat.fromAD(gregorianDate);
```

Retrieve relative dates:
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/navigating-dates/_meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"get-next-year": "getNextYear",
"get-previous-year": "getPreviousYear",
"to-gregorian": "toGregorian",
"to-ad": "toAD",
"add-years": "addYears",
"add-months": "addMonths",
"add-days": "addDays",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### `toGregorian(): Date`
### `toAD(): Date`

Converts the Bikram Sambat date to the corresponding Gregorian date.

```jsx copy
const date = new BikramSambat('2078-05-15')
const gregorianDate = date.toGregorian() // A JavaScript Date object
const gregorianDate = date.toAD() // A JavaScript Date object
```
4 changes: 2 additions & 2 deletions docs/pages/static-methods/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"to-gregorian": "toGregorian",
"to-bikram-sambat": "toBikramSambat",
"to-ad": "toAD",
"from-ad": "fromAD",
"get-weekday-names": "getWeekdayNames",
"get-month-names": "getMonthNames"
}
8 changes: 8 additions & 0 deletions docs/pages/static-methods/from-ad.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### `fromAD(date: Date | string | undefined): BikramSambat`

Converts a Gregorian date to the corresponding Bikram Sambat date.

```jsx copy
const gregorianDate = new Date()
const bsDate = BikramSambat.fromAD(gregorianDate)
```
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### `toGregorian(date: BikramSambat | string | undefined): Date`
### `toAD(date: BikramSambat | string | undefined): Date`

Converts a Bikram Sambat date to the corresponding Gregorian date.

```jsx copy
const bsDate = new BikramSambat('2078-05-15')
const gregorianDate = BikramSambat.toGregorian(bsDate)
const gregorianDate = BikramSambat.toAD(bsDate)
```
8 changes: 0 additions & 8 deletions docs/pages/static-methods/to-bikram-sambat.mdx

This file was deleted.

6 changes: 3 additions & 3 deletions docs/pages/table-of-contents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- [Navigating Dates](/navigating-dates)
- [getPreviousYear(): number](/navigating-dates/get-previous-year)
- [getNextYear(): number](/navigating-dates/get-next-year)
- [toGregorian(): Date](/navigating-dates/to-gregorian)
- [toAD(): Date](/navigating-dates/to-ad)
- [addYears(years: number): BikramSambat](/navigating-dates/add-years)
- [addMonths(months: number): BikramSambat](/navigating-dates/add-months)
- [addDays(days: number): BikramSambat](/navigating-dates/add-days)
Expand All @@ -44,7 +44,7 @@
- [startOfMonth(): BikramSambat](/fething-relative-dates/start-of-month)
- [endOfMonth(): BikramSambat](/fething-relative-dates/end-of-month)
- [Static Methods](/static-methods/)
- [toGregorian(date: BikramSambat | string | undefined): Date](/static-methods/to-gregorian)
- [toBikramSambat(date: Date | string | undefined): BikramSambat](/static-methods/to-bikram-sambat)
- [toAD(date: BikramSambat | string | undefined): Date](/static-methods/to-ad)
- [fromAD(date: Date | string | undefined): BikramSambat](/static-methods/from-ad)
- [getWeekdayNames(language?: LanguageCode): string[]](/static-methods/get-weekday-names)
- [getMonthNames(language?: LanguageCode): string[]](/static-methods/get-month-names)
10 changes: 4 additions & 6 deletions src/BikramSambat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,20 @@ describe('BikramSambat Class', () => {
it('should properly convert to Gregorian Date', () => {
sampleData.forEach(([bsDate, adDate]) => {
const bikramSambat = new BikramSambat(bsDate)
expect(bikramSambat.toGregorian().toISOString().slice(0, 10)).toBe(adDate)
expect(bikramSambat.toAD().toISOString().slice(0, 10)).toBe(adDate)
})
})
it('should properly convert to BikramSambat Date', () => {
sampleData.forEach(([bsDate, adDate]) => {
expect(BikramSambat.toBikramSambat(adDate).toString()).toBe(bsDate)
expect(BikramSambat.fromAD(adDate).toString()).toBe(bsDate)
})
})

it('should return Invalid Date for Invalid Date', () => {
const bikramSambat = new BikramSambat('2075-01-32')
const gregorianDate = new Date(InvalidDate)
expect(bikramSambat.toGregorian().toString()).toBe(InvalidDate)
expect(BikramSambat.toBikramSambat(gregorianDate).toString()).toBe(
InvalidDate
)
expect(bikramSambat.toAD().toString()).toBe(InvalidDate)
expect(BikramSambat.fromAD(gregorianDate).toString()).toBe(InvalidDate)
})

it('should return previous year', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/BikramSambat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class BikramSambat {
this.day = dateStr.getDay()
} else {
const currentDate = new Date().toISOString().slice(0, 10)
const currentBsDate = BikramSambat.toBikramSambat(currentDate)
const currentBsDate = BikramSambat.fromAD(currentDate)
this.year = currentBsDate.getYear()
this.month = currentBsDate.getMonth()
this.day = currentBsDate.getDay()
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class BikramSambat {
return this.year ? this.year + 1 : NaN
}

public toGregorian(): Date {
public toAD(): Date {
if (!this.year || !this.month || !this.day) {
return new Date(InvalidDate)
}
Expand All @@ -171,12 +171,12 @@ export default class BikramSambat {
return gregorianDate
}

public static toGregorian(date: BikramSambat | string | undefined): Date {
public static toAD(date: BikramSambat | string | undefined): Date {
const bsDate = new BikramSambat(date)
return bsDate.toGregorian()
return bsDate.toAD()
}

public static toBikramSambat(date: Date | string | undefined): BikramSambat {
public static fromAD(date: Date | string | undefined): BikramSambat {
if (!date) {
return new BikramSambat()
}
Expand Down Expand Up @@ -301,7 +301,7 @@ export default class BikramSambat {
if (this.year === undefined || this.month === undefined) {
return NaN
}
const dateInGregorian = this.toGregorian()
const dateInGregorian = this.toAD()
const dayOfWeek = dateInGregorian.getDay()
return dayOfWeek
}
Expand Down