-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 241aef8
Showing
53 changed files
with
3,004 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# PersianJodaTime | ||
JodaTime with Persian/Solar calendar | ||
|
||
## Usage | ||
|
||
### Download | ||
|
||
1) Add JitPack repository in your root `build.gradle` at the end of `repositories` : | ||
|
||
```java | ||
|
||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
|
||
``` | ||
|
||
2) Add dependency to your root `build.gradle` : | ||
|
||
```java | ||
dependencies { | ||
... | ||
compile 'com.github.mohamadian:PersianJodaTime:1.2' | ||
} | ||
``` | ||
|
||
### Call JodaTimeAndroid.init() | ||
You must initialize the library before using it by calling `JodaTimeAndroid.init()`. I suggest putting this code in `Application.onCreate()` : | ||
|
||
```java | ||
public class MyApplication extends Application { | ||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
JodaTimeAndroid.init(this); | ||
} | ||
} | ||
``` | ||
|
||
and use `MyApplication` class in `AndroidManifest.xml` like this: | ||
```java | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mohamadian.testapp"> | ||
|
||
<application | ||
android:name=".MyApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> | ||
``` | ||
|
||
### How to create Persian DateTime and how to use it | ||
Ok, just create a `PersianChronology` object and pass it to `DateTime` class, all done: | ||
|
||
```java | ||
|
||
PersianChronology perChr = PersianChronologyKhayyam.getInstance(DateTimeZone.forID("Asia/Tehran")); | ||
DateTime now = new DateTime(perChr); | ||
|
||
DateTime dt = new DateTime(1396, 8, 2, 0, 0, perChr); | ||
``` | ||
|
||
### Credits | ||
This libary is based on [joda-time](https://github.com/JodaOrg/joda-time) and [zubinkavarana/joda-time](https://github.com/zubinkavarana/joda-time). | ||
|
||
### Thanks | ||
Special thanks to [zubinkavarana](https://github.com/zubinkavarana). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
defaultConfig { | ||
applicationId "com.mohamadian.persianjodatimeexample" | ||
minSdkVersion 16 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:27.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:0.5' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2' | ||
compile project(path: ':persianjodatime') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/mohamadian/persianjodatimeexample/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mohamadian.persianjodatimeexample; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.mohamadian.persianjodatimeexample", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mohamadian.persianjodatimeexample"> | ||
|
||
<application | ||
android:name=".MyApp" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/mohamadian/persianjodatimeexample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.mohamadian.persianjodatimeexample; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import org.joda.time.DateTime; | ||
import org.joda.time.DateTimeZone; | ||
import org.joda.time.chrono.PersianChronology; | ||
import org.joda.time.chrono.PersianChronologyKhayyam; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private TextView textView; | ||
private PersianChronology perChr; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
perChr = PersianChronologyKhayyam.getInstance(DateTimeZone.forID("Asia/Tehran")); | ||
DateTime now = new DateTime(perChr); | ||
|
||
textView = (TextView) findViewById(R.id.text_view); | ||
textView.setText("Today is : "+ Integer.toString(now.getYear())+"/"+ Integer.toString(now.getMonthOfYear())+"/"+ Integer.toString(now.getDayOfMonth())); | ||
|
||
findViewById(R.id.next_month).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
DateTime dt = new DateTime(perChr).plusMonths(1); | ||
textView.setText("Next month : "+ Integer.toString(dt.getYear())+"/"+ Integer.toString(dt.getMonthOfYear())+"/"+ Integer.toString(dt.getDayOfMonth())); | ||
} | ||
}); | ||
|
||
findViewById(R.id.specific_date).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
DateTime dt = new DateTime(1398, 12, 25, 0, 0, perChr); | ||
textView.setText("Specific date : "+ Integer.toString(dt.getYear())+"/"+ Integer.toString(dt.getMonthOfYear())+"/"+ Integer.toString(dt.getDayOfMonth())); | ||
} | ||
}); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/mohamadian/persianjodatimeexample/MyApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mohamadian.persianjodatimeexample; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
|
||
import net.danlew.android.joda.JodaTimeAndroid; | ||
|
||
/** | ||
* Created by Tasnim on 10/29/2017. | ||
*/ | ||
|
||
public class MyApp extends Application { | ||
private static Context mContext; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
JodaTimeAndroid.init(this); | ||
mContext = getApplicationContext(); | ||
} | ||
|
||
public static Context getContext() { | ||
return mContext; | ||
} | ||
} |
Oops, something went wrong.