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

Add Java Code Sample in README.md #3

Merged
merged 2 commits into from
Oct 23, 2024
Merged
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
92 changes: 86 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
![Unit Tests](https://github.com/hasancse91/bongabdo/actions/workflows/github-actions.yml/badge.svg)
[![](https://jitpack.io/v/hasancse91/bongabdo.svg)](https://jitpack.io/#hasancse91/bongabdo)

Bongabdo is a powerful Kotlin library that simplifies converting Gregorian dates to Bengali calendar dates (Bongabdo) for your Android or Java/Kotlin projects. It provides flexibility for regional variations and offers customization options. Check the Android sample project implementation. [From here](https://github.com/jamilxt/bongabdo-demo) you will find Spring Boot sample implementation.
Bongabdo is a powerful Kotlin library that simplifies converting Gregorian dates to Bengali calendar dates (Bongabdo) for your Android or Java/Kotlin projects. It provides flexibility for regional variations and offers customization options.

## Implementation:
- Android (Clone this repo to check the sample app)
- [Spring Boot (Kotlin)](https://github.com/jamilxt/bongabdo-demo)
- [Spring Boot (Java)](https://github.com/jamilxt/bongabdo-demo/tree/java)

## Demo (Android):
<img src="https://raw.githubusercontent.com/hasancse91/bongabdo/main/sample_data/sample-app-screenshot.jpeg" width="280" alt="bongabdo calendar library sample"/>

## Key Features:
Expand All @@ -21,7 +27,6 @@ Bongabdo is a powerful Kotlin library that simplifies converting Gregorian dates

#### Gradle Integration
For Gradle version 7.0 and above (`settings.gradle.kts`):

```kotlin
dependencyResolutionManagement {
repositories {
Expand All @@ -32,7 +37,7 @@ dependencyResolutionManagement {
}
```
For Gradle version below 7.0 (root level `build.gradle`)
```kotlin
```gradle
allprojects {
repositories {
mavenCentral()
Expand All @@ -56,6 +61,7 @@ Latest version:
To convert a Gregorian date to a Bengali date, initialize the `Bongabdo` class and call the appropriate conversion method.

Example: Convert a Gregorian Date to a Bengali Date (Bangla Academy Method)
> Kotlin
```kotlin
fun main() {
val bongabdo = Bongabdo.getInstance(BongabdoMethod.BANGLA_ACADEMY)
Expand All @@ -64,16 +70,34 @@ fun main() {
println("Bongabdo Date: ${result.getFullDate()}") // 1 Baishakh, 1431
}
```
> Java
```java
public class Main {
public static void main(String[] args) {
var bongabdo = Bongabdo.getInstance(BongabdoMethod.BANGLA_ACADEMY);
var result = bongabdo.getBongabdoData(2014, 3, 14); // 14 Apr 2024

System.out.println("Bongabdo Date: " + result.getFullDate()); // 1 Baishakh, 1431
}
}
```
-----
### 3. Localization Support
Bongabdo supports both English and Bengali locales. English is our default locale. You can set the desired locale using the configuration settings.

**Bengali Localization**
> Kotlin
```kotlin
bongabdo.mLocalizationConfig = BengaliLocalizationConfig()
bongabdo.localizationConfig = BengaliLocalizationConfig()
```
> Java
```java
bongabdo.setLocalizationConfig(new BengaliLocalizationConfig());
```

#### Custom Localization (e.g., Hindi)
You can extend the BongabdoLocalizationConfig class to add your own localization support.
> Kotlin
```kotlin
class HindiLocalisationConfig : BongabdoLocalizationConfig() {
override val digitMap: Map<Int, String>
Expand All @@ -86,29 +110,66 @@ class HindiLocalisationConfig : BongabdoLocalizationConfig() {

fun main() {
val bongabdo = Bongabdo.getInstance(BongabdoMethod.BANGLA_ACADEMY)
bongabdo.mLocalizationConfig = HindiLocalisationConfig()
bongabdo.localizationConfig = HindiLocalisationConfig()
val bongabdoData = bongabdo.getBongabdoData(2014, 3, 14)

println(bongabdoData.getFullDate())
}
```
> Java
```java
class HindiLocalizationConfig extends BongabdoLocalizationConfig {
@Override
public Map<Integer, String> getDigitMap() {
// TODO: Implement this method
}

@Override
public List<String> getMonthNameList() {
// TODO: Implement this method
}

@Override
public List<String> getSeasonNameList() {
// TODO: Implement this method
}
}

public class Main {
public static void main(String[] args) {
var bongabdo = Bongabdo.getInstance(BongabdoMethod.BANGLA_ACADEMY);
bongabdo.setLocalizationConfig(new HindiLocalizationConfig());
var bongabdoData = bongabdo.getBongabdoData(2014, 3, 14);

System.out.println(bongabdoData.getFullDate());
}
}
```
----
### 4. Calculation Method
Bongabdo currently supports two calculation methods:
1. Bangla Academy (used in Bangladesh)
2. Drik Shiddhanta (used in India)

Specify the calculation method during initialization:
> Kotlin
```kotlin
val bongabdo = Bongabdo.getInstance(BongabdoMethod.BANGLA_ACADEMY)`
val bongabdo = Bongabdo.getInstance(BongabdoMethod.BANGLA_ACADEMY)
// or
val bongabdo = Bongabdo.getInstance(BongabdoMethod.INDIAN_DRIK_SIDDHANTA)
```
> Java
```java
var bongabdo = Bongabdo.getInstance(BongabdoMethod.BANGLA_ACADEMY);
// or
var bongabdo = Bongabdo.getInstance(BongabdoMethod.INDIAN_DRIK_SIDDHANTA);
```
**Custom Calculation Methods**

To add a custom calculation method (e.g., Surya Shiddhanta), extend the Bongabdo class and implement the required logic.

Extend your own class from `Bongabdo` abstract class:
> Kotlin
```kotlin
class SurjaShiddhantaBongabdo : Bongabdo() {
override fun getBongabdoData(year: Int, month: Int, day: Int): BongabdoData {
Expand All @@ -124,6 +185,25 @@ fun main() {
println(bongabdoData.getFullDate())
}
```
> Java
```java
class SurjaShiddhantaBongabdo extends Bongabdo {
@Override
public BongabdoData getBongabdoData(int year, int month, int day) {
// TODO: Implement your logic here
}
}

public class Main {
public static void main(String[] args) {
var bongabdo = new SurjaShiddhantaBongabdo(); // your implemented class
bongabdo.setLocalizationConfig(new HindiLocalizationConfig()); // you can use your own localization class
var bongabdoData = bongabdo.getBongabdoData(2014, 3, 14);

System.out.println(bongabdoData.getFullDate());
}
}
```
----
In this way you can extend this library for localization and calculation method variation.

Expand Down
Loading