11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/Images/1.png
--------------------------------------------------------------------------------
/Images/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/Images/2.png
--------------------------------------------------------------------------------
/Images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/Images/3.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android multi calender tools library for android
2 | android date tools and date picker for tree calendar systems Jalali , Hijri , Gregorian
3 |
4 | # Screen shots
5 | primary color will be your theme color
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Add to your project
14 | copy [this](https://github.com/hooshkar/AndroidMultiCalenderTools/releases/download/1.5.0/uneversaldatetools-release.aar) to "yourProject/app/libs" [have problem?](https://github.com/hooshkar/AndroidMultiCalenderTools/wiki/install)
15 |
16 | # How to use
17 | date converter: more
18 | [here](https://github.com/hooshkar/AndroidMultiCalenderTools/wiki/Convert).
19 | ~~~java
20 | DateModel hijri = DateConverter.GregorianToHijri(2018, 1, 1);
21 | //hijri.day;
22 | //hijri.month;
23 | //hijri.year;
24 | ~~~
25 |
26 | date picker:
27 | xml:(don't change height and width)
28 | ~~~xml
29 |
33 | ~~~
34 | java:
35 | ~~~java
36 | UDatePicker uDatePicker = findViewById(R.id.date_picker);
37 |
38 | //push date to show in first time
39 | uDatePicker.ShowDatePicker(dateSystem);
40 |
41 | //or use current date
42 | uDatePicker.ShowDatePicker(Calendar.Jalali);
43 |
44 | //get on day selected event
45 | uDatePicker.setOnDateSelected((dateSystem, unixTime) -> {
46 | //do something...
47 | });
48 |
49 | //or get date when ever you want
50 | uDatePicker.getSelectedUnixTime();//as a unix time
51 | uDatePicker.getSelectedDate();//as a DateSystem object
52 |
53 | ~~~
54 |
55 | # Supported language:
56 | 1.persian
57 | 2.english
58 | and its easy to add new language see
59 | [here](https://github.com/hooshkar/AndroidMultiCalenderTools/wiki/language).
60 |
61 | # LICENCE
62 | under [MIT](https://github.com/hooshkar/AndroidMultiCalenderTools/blob/master/LICENSE) licence
63 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | signingConfigs {
5 | config {
6 | keyAlias 'ali'
7 | keyPassword 'ali'
8 | storeFile file('ali')
9 | storePassword 'ali'
10 | }
11 | }
12 | compileSdkVersion 27
13 | defaultConfig {
14 | applicationId "com.ali.universaldatetools"
15 | minSdkVersion 21
16 | targetSdkVersion 27
17 | versionCode 1
18 | versionName "1.0"
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | compileOptions {
28 | sourceCompatibility JavaVersion.VERSION_1_8
29 | targetCompatibility JavaVersion.VERSION_1_8
30 | }
31 | lintOptions {
32 | checkReleaseBuilds false
33 | // Or, if you prefer, you can continue to check for errors in release builds,
34 | // but continue the build even when errors are found:
35 | abortOnError false
36 | }
37 | }
38 |
39 | dependencies {
40 | implementation fileTree(include: ['*.jar'], dir: 'libs')
41 | implementation 'com.android.support:appcompat-v7:27.1.0'
42 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
43 | testImplementation 'junit:junit:4.12'
44 | androidTestImplementation 'com.android.support.test:runner:0.5'
45 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
46 | //implementation project(':uneversaldatetools')
47 | implementation project(':uneversaldatetools')
48 | }
49 |
--------------------------------------------------------------------------------
/app/libs/uneversaldatetools-debug.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/libs/uneversaldatetools-debug.aar
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/ali/universaldatetools/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ali.universaldatetools;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ali.universaldatetools", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ali/universaldatetools/DialogTestActivity.java:
--------------------------------------------------------------------------------
1 | package com.ali.universaldatetools;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.Button;
6 | import android.widget.Toast;
7 |
8 | import com.ali.uneversaldatetools.UDatePickerDialog;
9 | import com.ali.uneversaldatetools.date.DateSystem;
10 |
11 | public class DialogTestActivity extends AppCompatActivity implements UDatePickerDialog.UDatePickerDialogListener {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_dialog_test);
17 |
18 | Button showDialog = findViewById(R.id.btn_show_dialog);
19 |
20 | showDialog.setOnClickListener(v -> {
21 | UDatePickerDialog uDatePickerDialog = new UDatePickerDialog();
22 |
23 | uDatePickerDialog.setListener(this);
24 | uDatePickerDialog.show(getSupportFragmentManager(), "");
25 | });
26 | }
27 |
28 | @Override
29 | public void onCancel() {
30 | Toast.makeText(this, "cancel", Toast.LENGTH_SHORT).show();
31 | }
32 |
33 | @Override
34 | public void onSelect(long unixTime, DateSystem dateSystem) {
35 | Toast.makeText(this, dateSystem.toString(), Toast.LENGTH_SHORT).show();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ali/universaldatetools/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ali.universaldatetools;
2 |
3 | import android.content.Intent;
4 | import android.content.res.Resources;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.util.DisplayMetrics;
8 | import android.widget.Button;
9 | import android.widget.TextView;
10 | import android.widget.Toast;
11 |
12 | import com.ali.uneversaldatetools.date.Calendar;
13 | import com.ali.uneversaldatetools.datePicker.UDatePicker;
14 |
15 | import java.util.Locale;
16 |
17 | public class MainActivity extends AppCompatActivity {
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 |
24 | UDatePicker a = findViewById(R.id.date_picker);
25 | Button lang = findViewById(R.id.btn_lang);
26 | Button getTime = findViewById(R.id.btn_get_time);
27 | TextView timeView = findViewById(R.id.text_time_show);
28 |
29 | a.ShowDatePicker(getSupportFragmentManager(), Calendar.Jalali);
30 | a.setOnDateSelected((dateSystem, unixTime) -> {
31 | timeView.setText("unix time is: " + unixTime);
32 | timeView.append("\ndate is: " + dateSystem);
33 | });
34 |
35 | getTime.setOnClickListener(v -> {
36 | if (a.getSelectedUnixTime() == null) {
37 | Toast.makeText(this, "plz select day", Toast.LENGTH_SHORT).show();
38 | } else {
39 | timeView.setText("unix time is: " + a.getSelectedUnixTime());
40 | timeView.append("\ndate is: " + a.getSelectedDate());
41 | }
42 | });
43 |
44 | lang.setOnClickListener(v -> {
45 | if (getString(R.string.LangId).equals("en")) {
46 | setLocale("fa");
47 | } else {
48 | setLocale("en");
49 | }
50 | });
51 | }
52 |
53 | private void setLocale(String lng) {
54 | Resources res = getResources();
55 | // Change locale settings in the app.
56 | DisplayMetrics dm = res.getDisplayMetrics();
57 | android.content.res.Configuration conf = res.getConfiguration();
58 | conf.setLocale(new Locale(lng.toLowerCase())); // API 17+ only.
59 | // Use conf.locale = new Locale(...) if targeting lower versions
60 | res.updateConfiguration(conf, dm);
61 | finishAndRemoveTask();
62 | startActivity(new Intent(this, MainActivity.class));
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_dialog_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
23 |
29 |
30 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values-fa/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | fa
4 |
5 | UniversalDateTools
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UniversalDateTools
3 | en
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/ali/universaldatetools/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ali.universaldatetools;
2 |
3 | import org.junit.Test;
4 |
5 | /**
6 | * Example local unit test, which will execute on the development machine (host).
7 | *
8 | * @see Testing documentation
9 | */
10 | public class ExampleUnitTest {
11 |
12 | @Test
13 | public void test(){
14 |
15 |
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Sun Dec 02 12:49:46 IRST 2018
16 | systemProp.https.proxyPort=45853
17 | systemProp.http.proxyHost=127.0.0.1
18 | org.gradle.jvmargs=-Xmx1536m
19 | systemProp.https.proxyHost=127.0.0.1
20 | systemProp.http.proxyPort=45853
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 05 09:39:47 IRDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':uneversaldatetools'
2 |
--------------------------------------------------------------------------------
/uneversaldatetools/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/uneversaldatetools/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | minSdkVersion 15
7 | targetSdkVersion 27
8 | versionCode 1
9 | versionName "1.0"
10 |
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 |
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_8
22 | targetCompatibility JavaVersion.VERSION_1_8
23 | }
24 | productFlavors {
25 | }
26 | lintOptions {
27 | checkReleaseBuilds false
28 | // Or, if you prefer, you can continue to check for errors in release builds,
29 | // but continue the build even when errors are found:
30 | abortOnError false
31 | }
32 | }
33 |
34 |
35 | dependencies {
36 | implementation fileTree(include: ['*.jar'], dir: 'libs')
37 | implementation 'com.android.support:appcompat-v7:27.1.0'
38 | testImplementation 'junit:junit:4.12'
39 | androidTestImplementation 'com.android.support.test:runner:0.5'
40 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
41 | }
42 |
--------------------------------------------------------------------------------
/uneversaldatetools/libs/jars/universalDateTools.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hooshkar/AndroidMultiCalendarTools/01ad46a40c945cd49d9287e2912ac8f1bafc4c90/uneversaldatetools/libs/jars/universalDateTools.jar
--------------------------------------------------------------------------------
/uneversaldatetools/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/androidTest/java/com/ali/uneversaldatetools/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ali.uneversaldatetools.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/UDatePickerDialog.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Bundle;
5 | import android.support.v4.app.DialogFragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 |
11 | import com.ali.uneversaldatetools.date.Calendar;
12 | import com.ali.uneversaldatetools.date.DateSystem;
13 | import com.ali.uneversaldatetools.datePicker.UDatePicker;
14 |
15 | /**
16 | * Created by ali on 9/25/18.
17 | */
18 |
19 | @SuppressLint("ValidFragment")
20 | public class UDatePickerDialog extends DialogFragment {
21 |
22 |
23 | private UDatePickerDialogListener mListener;
24 |
25 | @Override
26 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
27 | View view = inflater.inflate(R.layout.dialog_u_date_picker, container);
28 |
29 | UDatePicker datePicker = view.findViewById(R.id.date_picker_dialog_date_picker);
30 | datePicker.ShowDatePicker(getChildFragmentManager(), Calendar.Jalali);
31 |
32 | Button select = view.findViewById(R.id.btn_dialog_select);
33 | Button cancel = view.findViewById(R.id.btn_dialog_cancel);
34 |
35 | select.setOnClickListener(v -> {
36 | if (mListener != null)
37 | mListener.onSelect(datePicker.getSelectedUnixTime(), datePicker.getSelectedDate());
38 | dismiss();
39 | });
40 |
41 | cancel.setOnClickListener(v -> {
42 | if (mListener != null)
43 | mListener.onCancel();
44 | dismiss();
45 | });
46 | return view;
47 | }
48 |
49 | public void setListener(UDatePickerDialogListener listener) {
50 | this.mListener = listener;
51 | }
52 |
53 | public interface UDatePickerDialogListener {
54 | void onCancel();
55 |
56 | void onSelect(long unixTime, DateSystem dateSystem);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/Calendar.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | /**
4 | * Created by ali on 9/5/18.
5 | */
6 |
7 | public enum Calendar {
8 | None(0),
9 | Gregorian(1),
10 | Jalali(2),
11 | Hijri(3);
12 |
13 | private final int value;
14 |
15 | Calendar(int value) {
16 | this.value = value;
17 | }
18 |
19 | public int getValue() {
20 | return value;
21 | }
22 |
23 | public static Calendar ToCalender(int num) {
24 | switch (num) {
25 | case 0:
26 | return None;
27 | case 1:
28 | return Gregorian;
29 | case 2:
30 | return Jalali;
31 | case 3:
32 | return Hijri;
33 | }
34 | return null;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/DateConverter.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | import com.ali.uneversaldatetools.model.DateModel;
4 |
5 | /**
6 | * Created by ali on 9/5/18.
7 | */
8 |
9 | public class DateConverter {
10 |
11 | public static boolean IsJalaliLeap(int year) {
12 | if (year >= 1 && year <= 474) {
13 | year += 2346;
14 | } else if (year > 474) {
15 | year -= 474;
16 | }
17 |
18 | year = year % 2820;
19 |
20 | year = year % 128;
21 |
22 | year -= year >= 29 ? 29 : 0;
23 |
24 | year = year % 33;
25 |
26 | year -= year >= 5 ? 5 : 0;
27 |
28 | year = year % 4;
29 |
30 | return year == 0;
31 | }
32 |
33 | public static boolean IsGregorianLeap(int year) {
34 | return year % 400 == 0 || (year % 100 != 0 & year % 4 == 0);
35 | }
36 |
37 | public static boolean IsHijriLeap(int year) {
38 | int[] yearsLeap = {2, 5, 7, 10, 13, 15, 18, 21, 24, 26, 29};
39 |
40 | year = year % 30;
41 |
42 | for (int i = 0; i < 11; i++) {
43 | if (year == yearsLeap[i]) {
44 | return true;
45 | }
46 | }
47 |
48 | return false;
49 | }
50 |
51 |
52 | public static int JalaliToDays(int year, int month, int day) {
53 | return day +
54 | (month - 1 <= 6 ? (month - 1) * 31 : (month - 1) * 30 + 6) +
55 | (year - 1) * 365 +
56 | LeapsJalaliBehind(year - 1);
57 | }
58 |
59 | public static int GregorianToDays(int year, int month, int day) {
60 | int[] monthDays = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
61 |
62 | return day +
63 | monthDays[month - 1] +
64 | (year - 1) * 365 +
65 | LeapsGregorianBehind(year) +
66 | ((month - 1 >= 2) && IsGregorianLeap(year) ? 1 : 0);
67 | }
68 |
69 | public static int HijriToDays(int year, int month, int day) {
70 | int[] monthDays = {0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325};
71 |
72 | return day + monthDays[month - 1] + (year - 1) * 354 + LeapsHijriBehind(year - 1);
73 | }
74 |
75 |
76 | static DateModel DaysToJalali(int days) {
77 |
78 | DateModel jalali = new DateModel();
79 |
80 | if (days >= 1 & days <= 173125) {
81 | jalali.year -= 2346;
82 | days += 856858;
83 | } else if (days > 173125) {
84 | jalali.year += 474;
85 | days -= 173125;
86 | }
87 |
88 | jalali.year += (days / 1029983) * 2820;
89 |
90 | days = days % 1029983;
91 |
92 | jalali.year += (days / 46751) * 128;
93 |
94 | days = days % 46751;
95 |
96 | if (days >= 10592) {
97 | jalali.year += 29;
98 |
99 | days -= 10592;
100 |
101 | jalali.year += (days / 12053) * 33;
102 |
103 | days = days % 12053;
104 |
105 | if (days >= 1826) {
106 | jalali.year += 5;
107 |
108 | days -= 1826;
109 |
110 | jalali.year += (days / 1461) * 4;
111 |
112 | days = days % 1461;
113 | }
114 | } else if (days >= 1826) {
115 | jalali.year += 5;
116 |
117 | days -= 1826;
118 |
119 | jalali.year += (days / 1461) * 4;
120 |
121 | days = days % 1461;
122 | }
123 |
124 | if (days == 0 & IsJalaliLeap(jalali.year)) {
125 | jalali.year -= 1;
126 | days = 366;
127 | } else if (days == 1460) {
128 | jalali.year += 3;
129 | days = 365;
130 | } else {
131 | jalali.year += days / 365;
132 | days = days % 365;
133 | if (days == 0) {
134 | jalali.year -= 1;
135 | days = 365;
136 | }
137 | }
138 |
139 | if (days > 336) {
140 | jalali.month = 11;
141 | jalali.day = days - 336;
142 | } else if (days > 306) {
143 | jalali.month = 10;
144 | jalali.day = days - 306;
145 | } else if (days > 276) {
146 | jalali.month = 9;
147 | jalali.day = days - 276;
148 | } else if (days > 246) {
149 | jalali.month = 8;
150 | jalali.day = days - 246;
151 | } else if (days > 216) {
152 | jalali.month = 7;
153 | jalali.day = days - 216;
154 | } else if (days > 186) {
155 | jalali.month = 6;
156 | jalali.day = days - 186;
157 | } else if (days > 155) {
158 | jalali.month = 5;
159 | jalali.day = days - 155;
160 | } else if (days > 124) {
161 | jalali.month = 4;
162 | jalali.day = days - 124;
163 | } else if (days > 93) {
164 | jalali.month = 3;
165 | jalali.day = days - 93;
166 | } else if (days > 62) {
167 | jalali.month = 2;
168 | jalali.day = days - 62;
169 | } else if (days > 31) {
170 | jalali.month = 1;
171 | jalali.day = days - 31;
172 | } else {
173 | jalali.day = days;
174 | }
175 |
176 | jalali.year += 1;
177 |
178 | jalali.month += 1;
179 |
180 | return jalali;
181 | }
182 |
183 | static DateModel DaysToGregorian(int days) {
184 |
185 | DateModel miladi = new DateModel();
186 |
187 | int quadricent = days / 146097;
188 |
189 | days = days % 146097;
190 |
191 | int cent = days / 36524;
192 |
193 | days = days % 36524;
194 |
195 | int quad = days / 1461;
196 |
197 | days = days % 1461;
198 |
199 | miladi.year = (quadricent * 400 + cent * 100 + quad * 4);
200 |
201 | int one = 0;
202 |
203 | if (days == 0 & IsGregorianLeap(miladi.year)) {
204 | one -= 1;
205 | days = 366;
206 | } else if (days == 1460) {
207 | one = 3;
208 | days = 365;
209 | } else {
210 | one = days / 365;
211 | days = days % 365;
212 | if (days == 0) {
213 | one -= 1;
214 | days = 365;
215 | }
216 | }
217 |
218 | miladi.year += one;
219 |
220 | if (IsGregorianLeap(miladi.year + 1)) {
221 | days--;
222 | }
223 | if (days > 334) {
224 | miladi.month = 11;
225 | miladi.day = days - 334;
226 | } else if (days > 304) {
227 | miladi.month = 10;
228 | miladi.day = days - 304;
229 | } else if (days > 273) {
230 | miladi.month = 9;
231 | miladi.day = days - 273;
232 | } else if (days > 243) {
233 | miladi.month = 8;
234 | miladi.day = days - 243;
235 | } else if (days > 212) {
236 | miladi.month = 7;
237 | miladi.day = days - 212;
238 | } else if (days > 181) {
239 | miladi.month = 6;
240 | miladi.day = days - 181;
241 | } else if (days > 151) {
242 | miladi.month = 5;
243 | miladi.day = days - 151;
244 | } else if (days > 120) {
245 | miladi.month = 4;
246 | miladi.day = days - 120;
247 | } else if (days > 90) {
248 | miladi.month = 3;
249 | miladi.day = days - 90;
250 | } else if (days > 59) {
251 | miladi.month = 2;
252 | miladi.day = days - 59;
253 | } else if (days > 31) {
254 | miladi.month = 1;
255 | miladi.day = days - 31;
256 |
257 | if (IsGregorianLeap(miladi.year + 1)) {
258 | miladi.day++;
259 | }
260 | } else if (IsGregorianLeap(miladi.year + 1) & days == 31) {
261 | miladi.month = 1;
262 | miladi.day = 1;
263 | } else {
264 | miladi.day = days;
265 |
266 | if (IsGregorianLeap(miladi.year + 1)) {
267 | miladi.day++;
268 | }
269 | }
270 |
271 | miladi.year += 1;
272 | miladi.month += 1;
273 |
274 | return miladi;
275 | }
276 |
277 | static DateModel DaysToHijri(int days) {
278 |
279 | DateModel hijri = new DateModel();
280 |
281 | hijri.year = days / 10631 * 30;
282 |
283 | days = days % 10631;
284 |
285 | if (days >= 10277) {
286 | days -= 10277;
287 | hijri.year += 29;
288 | } else if (days >= 9214) {
289 | days -= 9214;
290 | hijri.year += 26;
291 | } else if (days >= 8505) {
292 | days -= 8505;
293 | hijri.year += 24;
294 | } else if (days >= 7442) {
295 | days -= 7442;
296 | hijri.year += 21;
297 | } else if (days >= 6379) {
298 | days -= 6379;
299 | hijri.year += 18;
300 | } else if (days >= 5316) {
301 | days -= 5316;
302 | hijri.year += 15;
303 | } else if (days >= 4607) {
304 | days -= 4607;
305 | hijri.year += 13;
306 | } else if (days >= 3544) {
307 | days -= 3544;
308 | hijri.year += 10;
309 | } else if (days >= 2481) {
310 | days -= 2481;
311 | hijri.year += 7;
312 | } else if (days >= 1772) {
313 | days -= 1772;
314 | hijri.year += 5;
315 | } else if (days >= 709) {
316 | days -= 709;
317 | hijri.year += 2;
318 | }
319 |
320 | if (days == 0 & IsHijriLeap(hijri.year)) {
321 | hijri.year -= 1;
322 | days = 355;
323 | } else {
324 | hijri.year += days / 354;
325 |
326 | days = days % 354;
327 |
328 | if (days == 0) {
329 | hijri.year -= 1;
330 | days = 354;
331 | }
332 | }
333 |
334 | if (days > 325) {
335 | hijri.month = 11;
336 | hijri.day = days - 325;
337 | } else if (days > 295) {
338 | hijri.month = 10;
339 | hijri.day = days - 295;
340 | } else if (days > 266) {
341 | hijri.month = 9;
342 | hijri.day = days - 266;
343 | } else if (days > 236) {
344 | hijri.month = 8;
345 | hijri.day = days - 236;
346 | } else if (days > 207) {
347 | hijri.month = 7;
348 | hijri.day = days - 207;
349 | } else if (days > 177) {
350 | hijri.month = 6;
351 | hijri.day = days - 177;
352 | } else if (days > 148) {
353 | hijri.month = 5;
354 | hijri.day = days - 148;
355 | } else if (days > 118) {
356 | hijri.month = 4;
357 | hijri.day = days - 118;
358 | } else if (days > 89) {
359 | hijri.month = 3;
360 | hijri.day = days - 89;
361 | } else if (days > 59) {
362 | hijri.month = 2;
363 | hijri.day = days - 59;
364 | } else if (days > 30) {
365 | hijri.month = 1;
366 | hijri.day = days - 30;
367 | } else {
368 | hijri.day = days;
369 | }
370 |
371 | hijri.year += 1;
372 | hijri.month += 1;
373 |
374 | return hijri;
375 | }
376 |
377 |
378 | private static int LeapsJalaliBehind(int year) {
379 | int leaps = 0;
380 |
381 | if (year >= 1 & year <= 474) {
382 | year += 2346;
383 |
384 | leaps -= 568;
385 | } else if (year > 474) {
386 | year -= 474;
387 |
388 | leaps += 115;
389 | }
390 |
391 | leaps += year / 2820 * 683;
392 |
393 | year = year % 2820;
394 |
395 | leaps += year / 128 * 31;
396 |
397 | year = year % 128;
398 |
399 | if (year >= 29) {
400 | year -= 29;
401 |
402 | leaps += 7;
403 |
404 | leaps += year / 33 * 8;
405 |
406 | year = year % 33;
407 |
408 | if (year < 5) {
409 | return leaps;
410 | }
411 |
412 | year -= 5;
413 |
414 | leaps += 1;
415 |
416 | leaps += year / 4;
417 | } else {
418 | if (year < 5) {
419 | return leaps;
420 | }
421 |
422 | year -= 5;
423 |
424 | leaps += 1;
425 |
426 | leaps += year / 4;
427 | }
428 |
429 | return leaps;
430 | }
431 |
432 | private static int LeapsGregorianBehind(int year) {
433 | return ((year - 1) / 4) + ((year - 1) / 400) - ((year - 1) / 100);
434 | }
435 |
436 | private static int LeapsHijriBehind(int year) {
437 | int leaps = year / 30 * 11;
438 |
439 | year = year % 30;
440 |
441 | if (year >= 29) leaps += 11;
442 | else if (year >= 26)
443 | leaps += 10;
444 | else if (year >= 24)
445 | leaps += 9;
446 | else if (year >= 21)
447 | leaps += 8;
448 | else if (year >= 18)
449 | leaps += 7;
450 | else if (year >= 15)
451 | leaps += 6;
452 | else if (year >= 13)
453 | leaps += 5;
454 | else if (year >= 10)
455 | leaps += 4;
456 | else if (year >= 7)
457 | leaps += 3;
458 | else if (year >= 5)
459 | leaps += 2;
460 | else if (year >= 2)
461 | leaps += 1;
462 | return leaps;
463 | }
464 |
465 |
466 | public static DateModel JalaliToGregorian(int year, int month, int day) {
467 | return DaysToGregorian(JalaliToDays(year, month, day) + 226895);
468 | }
469 |
470 | public static DateModel JalaliToHijri(int year, int month, int day) {
471 | return DaysToHijri(JalaliToDays(year, month, day) - 119);
472 | }
473 |
474 | public static DateModel GregorianToJalali(int year, int month, int day) {
475 | return DaysToJalali(GregorianToDays(year, month, day) - 226895);
476 | }
477 |
478 | public static DateModel GregorianToHijri(int year, int month, int day) {
479 | return DaysToHijri(GregorianToDays(year, month, day) - 227014);
480 | }
481 |
482 | public static DateModel HijriToJalali(int year, int month, int day) {
483 | return DaysToJalali(HijriToDays(year, month, day) + 119);
484 | }
485 |
486 | public static DateModel HijriToGregorian(int year, int month, int day) {
487 | return DaysToGregorian(HijriToDays(year, month, day) + 227014);
488 | }
489 |
490 | //unix time
491 |
492 | public static DateModel UnixToHijri(int sec) {
493 | DateModel date = DaysToHijri((sec / 86400) + 719163 - 227014);
494 | date.sec = sec % 86400;
495 | date.hour = date.sec / 3600;
496 | date.sec = date.sec % 3600;
497 | date.min = date.sec / 60;
498 | date.sec = date.sec % 60;
499 | return date;
500 | }
501 |
502 | public static DateModel UnixToJalali(int sec) {
503 | DateModel date = DaysToJalali((sec / 86400) + 719163 - 226895);
504 | date.sec = sec % 86400;
505 | date.hour = date.sec / 3600;
506 | date.sec = date.sec % 3600;
507 | date.min = date.sec / 60;
508 | date.sec = date.sec % 60;
509 | return date;
510 | }
511 |
512 | public static DateModel UnixToGregorian(int sec) {
513 | DateModel date = DaysToGregorian((sec / 86400) + 719163);
514 | date.sec = sec % 86400;
515 | date.hour = date.sec / 3600;
516 | date.sec = date.sec % 3600;
517 | date.min = date.sec / 60;
518 | date.sec = date.sec % 60;
519 | return date;
520 | }
521 |
522 |
523 | public static int HijriToUnix(int year, int month, int day, int hour, int min, int sec) {
524 |
525 | int from = 719163; // const : DateConverter.GregorianToDays(1970, 1, 1)
526 |
527 | from -= 227014; // hijri and gregorian deference in days
528 |
529 | int days = HijriToDays(year, month, day);
530 |
531 | int lastDays = ((days - from) * 86400);
532 |
533 | int today = sec + (min * 60) + (hour * 3600);
534 |
535 | return today + lastDays;
536 |
537 | }
538 |
539 | public static int JalaliToUnix(int year, int month, int day, int hour, int min, int sec) {
540 |
541 | int from = 719163; // const : DateConverter.GregorianToDays(1970, 1, 1)
542 |
543 | from -= 226895; // jalali and gregorian deference in days
544 |
545 | int days = JalaliToDays(year, month, day);
546 |
547 | int lastDays = ((days - from) * 86400);
548 |
549 | int today = sec + (min * 60) + (hour * 3600);
550 |
551 | return today + lastDays;
552 | }
553 |
554 | public static int GregorianToUnix(int year, int month, int day, int hour, int min, int sec) {
555 |
556 | int from = 719163; // const -> DateConverter.GregorianToDays(1970, 1, 1)
557 |
558 | int days = GregorianToDays(year, month, day);
559 |
560 | int lastDays = ((days - from) * 86400);
561 |
562 | int today = sec + (min * 60) + (hour * 3600);
563 |
564 | return today + lastDays;
565 | }
566 | }
567 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/DateSystem.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | import android.os.Build;
4 | import android.support.annotation.Nullable;
5 | import android.support.annotation.RequiresApi;
6 | import android.util.Log;
7 |
8 | import com.ali.uneversaldatetools.model.DateModel;
9 | import com.ali.uneversaldatetools.tools.UnixTimeTools;
10 |
11 | import java.util.Date;
12 | import java.util.Objects;
13 | import java.util.TimeZone;
14 |
15 | /**
16 | * Created by ali on 9/5/18.
17 | */
18 |
19 | public class DateSystem implements IDate {
20 |
21 | private Calendar Calendar;
22 | private DateModel Date;
23 | private IDate Date_SD;
24 |
25 | public DateSystem(int year, int month, int day, Calendar calendar) {
26 | Calendar = calendar;
27 |
28 | Log.d("month: ", String.valueOf(month));
29 | if (month > 12) month -= 12;
30 |
31 | switch (Calendar) {
32 |
33 | case Jalali:
34 | Date_SD = new JalaliDateTime(year, month, day);
35 | break;
36 |
37 | case Gregorian:
38 | Date_SD = new GregorianDateTime(year, month, day);
39 | break;
40 |
41 | case Hijri:
42 | Date_SD = new HijriDateTime(year, month, day);
43 | break;
44 |
45 | default:
46 | throw new RuntimeException("Invalid Calendar Type!");
47 |
48 | }
49 | Date = Date_SD.getDate();
50 | }
51 |
52 | public DateSystem(int year, int month, int day, int hour, int min, int sec, TimeZone timeZone, Calendar calendar) {
53 | Calendar = calendar;
54 |
55 | Log.d("month: ", String.valueOf(month));
56 | if (month > 12) month -= 12;
57 |
58 | switch (Calendar) {
59 |
60 | case Jalali:
61 | Date_SD = new JalaliDateTime(year, month, day, hour, min, sec, timeZone);
62 | break;
63 |
64 | case Gregorian:
65 | Date_SD = new GregorianDateTime(year, month, day, hour, min, sec, timeZone);
66 | break;
67 |
68 | case Hijri:
69 | Date_SD = new HijriDateTime(year, month, day, hour, min, sec, timeZone);
70 | break;
71 |
72 | default:
73 | throw new RuntimeException("Invalid Calendar Type!");
74 |
75 | }
76 | Date = Date_SD.getDate();
77 | }
78 |
79 | public DateSystem(int unixTime, TimeZone timeZone, Calendar calendar) {
80 | Calendar = calendar;
81 |
82 | switch (Calendar) {
83 |
84 | case Jalali:
85 | Date_SD = new JalaliDateTime(unixTime, timeZone);
86 | break;
87 |
88 | case Gregorian:
89 | Date_SD = new GregorianDateTime(unixTime, timeZone);
90 | break;
91 |
92 | case Hijri:
93 | Date_SD = new HijriDateTime(unixTime, timeZone);
94 | break;
95 |
96 | default:
97 | throw new RuntimeException("Invalid Calendar Type!");
98 |
99 | }
100 | Date = Date_SD.getDate();
101 | }
102 |
103 | public Calendar getCalendar() {
104 | return Calendar;
105 | }
106 |
107 | public DateModel getDate() {
108 | return Date;
109 | }
110 |
111 | public JalaliDateTime getJalaliDateTime() {
112 | return Date_SD.getJalaliDateTime();
113 | }
114 |
115 | public GregorianDateTime getGregorianDateTime() {
116 | return Date_SD.getGregorianDateTime();
117 | }
118 |
119 | public HijriDateTime getHijriDateTime() {
120 | return Date_SD.getHijriDateTime();
121 | }
122 |
123 | public IDate getDate_SD() {
124 | return Date_SD;
125 | }
126 |
127 | public int getYear() {
128 | return Date_SD.getYear();
129 | }
130 |
131 | public int getMonth() {
132 | return Date_SD.getMonth();
133 | }
134 |
135 | public int getDay() {
136 | return Date_SD.getDay();
137 | }
138 |
139 | @Override
140 | public int getHour() {
141 | return Date_SD.getHour();
142 | }
143 |
144 | @Override
145 | public int getMin() {
146 | return Date_SD.getMin();
147 | }
148 |
149 | @Override
150 | public int getSec() {
151 | return Date_SD.getSec();
152 | }
153 |
154 | public int getDays() {
155 | return Date_SD.getDays();
156 | }
157 |
158 | public DateModel getFirstDayOfYear() {
159 | return Date_SD.getFirstDayOfYear();
160 | }
161 |
162 | public DateModel getLastDayOfYear() {
163 | return Date_SD.getLastDayOfYear();
164 | }
165 |
166 | public DateModel getFirstDayOfMonth() {
167 | return Date_SD.getFirstDayOfMonth();
168 | }
169 |
170 | public DateModel getLastDayOfMonth() {
171 | return Date_SD.getLastDayOfMonth();
172 | }
173 |
174 | public DateModel FirstDayOfSeason(Season season) {
175 | return Date_SD.FirstDayOfSeason(season);
176 | }
177 |
178 | public DateModel LastDayOfSeason(Season season) {
179 | return Date_SD.LastDayOfSeason(season);
180 | }
181 |
182 | public Season getSeason() {
183 | return Date_SD.getSeason();
184 | }
185 |
186 | public DayOfWeek getDayOfWeek() {
187 | return Date_SD.getDayOfWeek();
188 | }
189 |
190 | public int getDaysOfMonth() {
191 | return Date_SD.getDaysOfMonth();
192 | }
193 |
194 | public String getLetters() {
195 | return Date_SD.getLetters();
196 | }
197 |
198 | public String getMonthLetters() {
199 | return Date_SD.getMonthLetters();
200 | }
201 |
202 | public String getYearMonthLetters() {
203 | return Date_SD.getYearMonthLetters();
204 | }
205 |
206 | public DateModel AddYears(int years) {
207 | return Date_SD.AddYears(years);
208 | }
209 |
210 | public DateModel AddMonths(int months) {
211 | return Date_SD.AddMonths(months);
212 | }
213 |
214 | public DateModel AddDays(int days) {
215 | return Date_SD.AddDays(days);
216 | }
217 |
218 | public static DateSystem Now(TimeZone timeZone, Calendar calendar) {
219 | return new DateSystem(UnixTimeTools.getCurrentUnixTime(), timeZone, calendar);
220 | }
221 |
222 | public static DateSystem Parse(String date, Calendar calendar) {
223 | switch (calendar) {
224 | case Jalali: {
225 | DateModel d = JalaliDateTime.Parse(date).getDate();
226 | return new DateSystem(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZoneHelper.getSystemTimeZone(), calendar);
227 | }
228 | case Gregorian: {
229 | DateModel d = GregorianDateTime.Parse(date).getDate();
230 | return new DateSystem(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZoneHelper.getSystemTimeZone(), calendar);
231 | }
232 | case Hijri: {
233 | DateModel d = HijriDateTime.Parse(date).getDate();
234 | return new DateSystem(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZoneHelper.getSystemTimeZone(), calendar);
235 | }
236 | default: {
237 | throw new RuntimeException("Invalid Calendar Type!");
238 | }
239 | }
240 | }
241 |
242 | public static DateSystem Parse(String yearMonth, int day, Calendar calendar) {
243 | switch (calendar) {
244 | case Jalali: {
245 | DateModel d = JalaliDateTime.Parse(yearMonth, day).getDate();
246 | return new DateSystem(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZoneHelper.getSystemTimeZone(), calendar);
247 | }
248 | case Gregorian: {
249 | DateModel d = GregorianDateTime.Parse(yearMonth, day).getDate();
250 | return new DateSystem(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZoneHelper.getSystemTimeZone(), calendar);
251 | }
252 | case Hijri: {
253 | DateModel d = HijriDateTime.Parse(yearMonth, day).getDate();
254 | return new DateSystem(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZoneHelper.getSystemTimeZone(), calendar);
255 | }
256 | default: {
257 | throw new RuntimeException("Invalid Calendar Type!");
258 | }
259 | }
260 | }
261 |
262 | @Nullable
263 | public static Date ParseOrNull(String date) {
264 | try {
265 | long binary = 0;
266 | date = date.replace(" ", "");//Trim()
267 | try {
268 | Long.parseLong(date, (int) binary);
269 | return null; //todo last was return java.util.Date. (binary);
270 | } catch (NumberFormatException e) {
271 | return new Date(java.util.Date.parse(date));
272 | }
273 | } catch (Exception e) {
274 | return null;
275 | }
276 | }
277 |
278 | public String getToYearMonth() {
279 | return Date_SD.getToYearMonth();
280 | }
281 |
282 | public String toString() {
283 | return Date_SD.toString();
284 | }
285 |
286 | // @Override
287 | // public int compareTo(@NonNull IDate o) {
288 | // return CompareTo(o);
289 | // }
290 | //
291 | // public int CompareTo(IDate t2) {
292 | // return Date.compareTo(t2);
293 | // }
294 |
295 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
296 | public boolean equals(DateSystem other) {
297 | return Calendar == other.Calendar && Objects.equals(Date_SD, other.Date_SD);
298 | }
299 |
300 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
301 | public boolean equals(Object obj) {
302 | return null != obj && obj instanceof DateSystem && equals((DateSystem) obj);
303 | }
304 |
305 | public int hashCode() {
306 | return (Calendar.getValue() * 397) ^ (Date_SD.hashCode());
307 | }
308 |
309 | public int toUnixTime() {
310 | return Date_SD.toUnixTime();
311 | }
312 | }
313 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/DateValidation.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | /**
4 | * Created by ali on 10/2/18.
5 | */
6 |
7 | public class DateValidation {
8 |
9 |
10 | public static void GregorianValidate(int year, int month, int day, int hour, int min, int sec) {
11 | BaseValidate(year,month,hour, min, sec);
12 | GregorianDayValidate(year, month, day);
13 | }
14 |
15 | public static void JalaliValidate(int year, int month, int day, int hour, int min, int sec) {
16 | BaseValidate(year,month,hour, min, sec);
17 | JalaliDayValidate(year, month, day);
18 | }
19 |
20 | public static void HijriValidate(int year, int month, int day, int hour, int min, int sec) {
21 | BaseValidate(year,month,hour, min, sec);
22 | HijriDayValidate(year, month, day);
23 | }
24 |
25 |
26 | private static void GregorianDayValidate(int year, int month, int day) {
27 |
28 | //day
29 | if (DateConverter.IsGregorianLeap(year) & month == 2) {
30 | if (day < 1 | day > GregorianDateTime.DaysInMonth[month] + 1)
31 | NotValid("day",day);
32 | } else {
33 | if (day < 1 | day > GregorianDateTime.DaysInMonth[month])
34 | NotValid("day",day);
35 | }
36 |
37 | }
38 |
39 | private static void JalaliDayValidate(int year, int month, int day) {
40 |
41 | //day
42 | if (DateConverter.IsGregorianLeap(year) & month == 12) {
43 | if (day < 1 | day > JalaliDateTime.DaysInMonth[month] + 1)
44 | NotValid("day",day);
45 | } else {
46 | if (day < 1 | day > JalaliDateTime.DaysInMonth[month])
47 | NotValid("day",day);
48 | }
49 |
50 | }
51 |
52 | private static void HijriDayValidate(int year, int month, int day) {
53 | //day
54 | if (DateConverter.IsGregorianLeap(year) & month == 12) {
55 | if (day < 1 | day > HijriDateTime.DaysInMonth[month] + 1)
56 | NotValid("day",day);
57 | } else {
58 | if (day < 1 | day > HijriDateTime.DaysInMonth[month])
59 | NotValid("day",day);
60 | }
61 | }
62 |
63 |
64 | private static void BaseValidate(int year, int month, int hour, int min, int sec) {
65 |
66 | //year
67 | if (year < 0) NotValid("year", year);
68 |
69 | //month
70 | if (month < 1 | month > 12) NotValid("month", month);
71 |
72 | //time
73 | if (hour > 23 | hour < 0) NotValid("hour", hour);
74 | if (min > 59 | min < 0) NotValid("minute", min);
75 | if (sec > 59 | sec < 0) NotValid("second", sec);
76 | }
77 |
78 |
79 | private static void NotValid(String what, int value) {
80 | throw new IllegalArgumentException("invalid " + what + " : " + value);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/DayOfWeek.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | /**
4 | * Created by ali on 9/5/18.
5 | */
6 |
7 | public enum DayOfWeek {
8 |
9 | Saturday(0),
10 | SunDay(1),
11 | Monday(2),
12 | Tuesday(3),
13 | Wednesday(4),
14 | Thursday(5),
15 | Friday(6);
16 |
17 | private final int value;
18 | DayOfWeek(int value) {
19 | this.value = value;
20 | }
21 |
22 | public int getValue() {
23 | return value;
24 | }
25 |
26 | public static DayOfWeek ToDayOfWeek(int num){
27 | switch (num){
28 | case 0: return Saturday;
29 | case 1: return SunDay;
30 | case 2: return Monday;
31 | case 3: return Tuesday;
32 | case 4: return Wednesday;
33 | case 5: return Thursday;
34 | case 6: return Friday;
35 | }
36 | return null;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/DefaultCalendar.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | /**
4 | * Created by ali on 9/30/18.
5 | */
6 |
7 | public class DefaultCalendar {
8 |
9 | private static Calendar mDefaultCalendar;
10 |
11 | public static Calendar getDefaultCalendar() {
12 | return mDefaultCalendar;
13 | }
14 |
15 | public static void setDefaultCalendar(Calendar DefaultCalendar) {
16 | mDefaultCalendar = DefaultCalendar;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/GregorianDateTime.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import com.ali.uneversaldatetools.model.DateModel;
6 | import com.ali.uneversaldatetools.tools.UnixTimeTools;
7 |
8 | import java.util.TimeZone;
9 |
10 | /**
11 | * Created by ali on 9/5/18.
12 | */
13 |
14 | public class GregorianDateTime implements IDate, Comparable {
15 |
16 | private int Year;
17 | private int Month;
18 | private int Day;
19 | private int Hour;
20 | private int Min;
21 | private int Sec;
22 | private TimeZone TimeZone;
23 |
24 | static final int[] DaysInMonth = {
25 | 0,
26 | 31,
27 | 29,
28 | 31,
29 | 30,
30 | 31,
31 | 30,
32 | 31,
33 | 31,
34 | 30,
35 | 31,
36 | 30,
37 | 31
38 | };
39 |
40 | public GregorianDateTime(int year, int month, int day) {
41 | DateValidation.GregorianValidate(year, month, day, 0, 0, 0);
42 | Year = year;
43 | Month = month;
44 | Day = day;
45 | TimeZone = TimeZoneHelper.getSystemTimeZone();
46 | }
47 |
48 | public GregorianDateTime(int year, int month, int day, int hour, int min, int sec, TimeZone timeZone) {
49 | this(year, month, day);
50 | DateValidation.GregorianValidate(year, month, day, hour, min, sec);
51 | Hour = hour;
52 | Min = min;
53 | Sec = sec;
54 | TimeZone = timeZone;
55 | }
56 |
57 | public GregorianDateTime(int days) {
58 | DateModel sd = DateConverter.DaysToGregorian(days);
59 | Year = sd.year;
60 | Month = sd.month;
61 | Day = sd.day;
62 | TimeZone = TimeZoneHelper.getSystemTimeZone();
63 | }
64 |
65 | public GregorianDateTime(int days, int hour, int min, int sec, TimeZone timeZone) {
66 | this(days);
67 | Hour = hour;
68 | Min = min;
69 | Sec = sec;
70 | TimeZone = timeZone;
71 | }
72 |
73 | public GregorianDateTime(int unixTimeSeconds, TimeZone timeZone) {
74 |
75 | int offset = TimeZoneHelper.ToSeconds(timeZone);
76 |
77 | DateModel dateModel = DateConverter.UnixToGregorian(unixTimeSeconds + offset);
78 | Year = dateModel.year;
79 | Month = dateModel.month;
80 | Day = dateModel.day;
81 | Hour = dateModel.hour;
82 | Min = dateModel.min;
83 | Sec = dateModel.sec;
84 | TimeZone = timeZone;
85 | }
86 |
87 |
88 | public static GregorianDateTime Parse(String s) {
89 | int y = Integer.valueOf(s.substring(0, 4));
90 | int m = Integer.valueOf(s.substring(5, 7));
91 | int d = Integer.valueOf(s.substring(8, 10));
92 | return new GregorianDateTime(y, m, d);
93 | }
94 |
95 | public static GregorianDateTime Parse(String yearMonth, int day) {
96 | int y = Integer.valueOf(yearMonth.substring(0, 4));
97 | int m = Integer.valueOf(yearMonth.substring(5, 7));
98 | return new GregorianDateTime(y, m, day);
99 | }
100 |
101 | public static GregorianDateTime ParseYearMonth(String s) {
102 | int y = Integer.valueOf(s.substring(0, 4));
103 | int m = Integer.valueOf(s.substring(5, 7));
104 | return new GregorianDateTime(y, m, 1);
105 | }
106 |
107 | public static GregorianDateTime Now() {
108 | return new GregorianDateTime(UnixTimeTools.getCurrentUnixTime(), TimeZoneHelper.getSystemTimeZone());
109 | }
110 |
111 |
112 | public DateModel getDate() {
113 | return new DateModel(Year, Month, Day);
114 | }
115 |
116 | public DateModel getFirstDayOfYear() {
117 | return new DateModel(Year, 1, 1);
118 | }
119 |
120 | public DateModel getLastDayOfYear() {
121 | return new DateModel(Year, 12, DaysInMonth[12], 23, 59, 59);
122 | }
123 |
124 | public DateModel getFirstDayOfMonth() {
125 | return new DateModel(Year, Month, 1);
126 | }
127 |
128 | public DateModel getLastDayOfMonth() {
129 | return new DateModel(Year, Month, DaysInMonth[Month] - (Month == 2 && !DateConverter.IsGregorianLeap(Year) ? 1 : 0), 23, 59, 59);
130 | }
131 |
132 | public DateModel FirstDayOfSeason(Season season) {
133 | int mSeason = season == Season.Winter ? 1 : season.getValue() + 1;
134 | int month = 1 + (mSeason - 1) * 3;
135 | return new GregorianDateTime(Year, month, 1).getDate();
136 | }
137 |
138 | public DateModel LastDayOfSeason(Season season) {
139 | int mSeason = season == Season.Winter ? 1 : season.getValue() + 1;
140 | int month = 3 + (mSeason - 1) * 3;
141 | int day = DaysInMonth[month] - (month == 2 && !DateConverter.IsGregorianLeap(Year) ? 1 : 0);
142 | return new DateModel(Year, month, day, 23, 59, 59);
143 | }
144 |
145 | public Season getSeason() {
146 |
147 | switch (Month) {
148 | case 1:
149 | case 2:
150 | case 3:
151 | return Season.Winter;
152 | case 4:
153 | case 5:
154 | case 6:
155 | return Season.Spring;
156 | case 7:
157 | case 8:
158 | case 9:
159 | return Season.Summer;
160 | case 10:
161 | case 11:
162 | case 12:
163 | return Season.Autumn;
164 | }
165 | throw new IndexOutOfBoundsException("month is not valid");
166 |
167 | }
168 |
169 | public DateModel AddYears(int years) {
170 | int y = Year + years;
171 | int m = Month;
172 | int maxd = DaysInMonth[m];
173 | maxd -= (m == 2 && !DateConverter.IsGregorianLeap(y) ? 1 : 0);
174 | int d = Day > maxd ? maxd : Day;
175 | return new GregorianDateTime(y, m, d).getDate();
176 | }
177 |
178 | public DateModel AddMonths(int months) {
179 | int m = Month - 1 + months;
180 | int y = Year + (m / 12);
181 | m = (m % 12) + 1;
182 | int maxd = DaysInMonth[m];
183 | maxd -= (m == 2 && !DateConverter.IsGregorianLeap(y) ? 1 : 0);
184 | int d = Day > maxd ? maxd : Day;
185 | return new GregorianDateTime(y, m, d).getDate();
186 | }
187 |
188 | public DateModel AddDays(int days) {
189 | return new GregorianDateTime(getDays() + days).getDate();
190 | }
191 |
192 | public JalaliDateTime getJalaliDateTime() {
193 | DateModel d = getDate();
194 | return new JalaliDateTime(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZone);
195 | }
196 |
197 | public GregorianDateTime getGregorianDateTime() {
198 | return this;
199 | }
200 |
201 | public HijriDateTime getHijriDateTime() {
202 | DateModel d = getDate();
203 | return new HijriDateTime(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZone);
204 | }
205 |
206 | public String getLetters() {
207 | return "";
208 | }
209 |
210 | public String getMonthLetters() {
211 | return "";
212 | }
213 |
214 | public String getYearMonthLetters() {
215 | return "";
216 | }
217 |
218 | public int getYear() {
219 | return Year;
220 | }
221 |
222 | public int getMonth() {
223 | return Month;
224 | }
225 |
226 | public int getDay() {
227 | return Day;
228 | }
229 |
230 | @Override
231 | public int getHour() {
232 | return Hour;
233 | }
234 |
235 | @Override
236 | public int getMin() {
237 | return Min;
238 | }
239 |
240 | @Override
241 | public int getSec() {
242 | return Sec;
243 | }
244 |
245 | public int getDays() {
246 | return DateConverter.GregorianToDays(Year, Month, Day);
247 | }
248 |
249 | public DayOfWeek getDayOfWeek() {
250 | return DayOfWeek.ToDayOfWeek((getDays() + 1) % 7);
251 | }
252 |
253 | public int getDaysOfMonth() {
254 | return DaysInMonth[Month] - (Month == 2 & !DateConverter.IsGregorianLeap(Year) ? 1 : 0);
255 | }
256 |
257 | public String getToYearMonth() {
258 | return String.format("%04d/%02d " + TimeZone.getDisplayName(), Year, Month);
259 | }
260 |
261 | public String toString() {
262 | return String.format("%04d/%02d/%02d " + TimeZone.getDisplayName(), Year, Month, Day);
263 | }
264 |
265 | public String toLongString() {
266 | return String.format("%04d/%02d/%02d %02d:%02d:%02d " + TimeZone.getDisplayName(), Year, Month, Day, Hour, Min, Sec);
267 | }
268 |
269 | @Override
270 | public int compareTo(@NonNull GregorianDateTime o) {
271 | return CompareTo(o);
272 | }
273 |
274 | public int CompareTo(IDate t2) {
275 | if (t2.getYear() > Year) return -1;
276 | if (t2.getYear() < Year) return 1;
277 | if (t2.getMonth() > Month) return -1;
278 | if (t2.getMonth() < Month) return 1;
279 | if (t2.getDay() > Day) return -1;
280 | return t2.getDay() == Day ? 0 : 1;
281 | }
282 |
283 | public boolean equals(GregorianDateTime other) {
284 | return Year == other.Year && Month == other.Month && Day == other.Day;
285 | }
286 |
287 | public boolean equals(Object obj) {
288 | if (null == obj) {
289 | return false;
290 | }
291 |
292 | return obj instanceof GregorianDateTime && equals((GregorianDateTime) obj);
293 | }
294 |
295 | public int hashCode() {
296 | int hashCode = Year;
297 | hashCode = (hashCode * 397) ^ Month;
298 | hashCode = (hashCode * 397) ^ Day;
299 | return hashCode;
300 | }
301 |
302 | @Override
303 | public int toUnixTime() {
304 | return DateConverter.GregorianToUnix(Year, Month, Day, Hour, Min, Sec) - TimeZoneHelper.ToSeconds(TimeZone);
305 | }
306 | }
307 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/HijriDateTime.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import com.ali.uneversaldatetools.model.DateModel;
6 | import com.ali.uneversaldatetools.tools.UnixTimeTools;
7 |
8 | import java.util.TimeZone;
9 |
10 | /**
11 | * Created by ali on 9/5/18.
12 | */
13 |
14 | public class HijriDateTime implements IDate, Comparable {
15 |
16 | private int Year;
17 | private int Month;
18 | private int Day;
19 | private int Hour;
20 | private int Min;
21 | private int Sec;
22 | private TimeZone TimeZone;
23 |
24 | static final int[] DaysInMonth = {
25 | 0,
26 | 30,
27 | 29,
28 | 30,
29 | 29,
30 | 30,
31 | 29,
32 | 30,
33 | 29,
34 | 30,
35 | 29,
36 | 30,
37 | 30
38 | };
39 |
40 | public HijriDateTime(int year, int month, int day) {
41 | DateValidation.HijriValidate(year, month, day, 0, 0, 0);
42 | Year = year;
43 | Month = month;
44 | Day = day;
45 | TimeZone = TimeZoneHelper.getSystemTimeZone();
46 | }
47 |
48 | public HijriDateTime(int year, int month, int day, int hour, int min, int sec, TimeZone timeZone) {
49 | this(year, month, day);
50 | DateValidation.HijriValidate(year, month, day, hour, min, sec);
51 | Hour = hour;
52 | Min = min;
53 | Sec = sec;
54 | TimeZone = timeZone;
55 | }
56 |
57 | public HijriDateTime(int days) {
58 | DateModel sd = DateConverter.DaysToHijri(days);
59 | Year = sd.year;
60 | Month = sd.month;
61 | Day = sd.day;
62 | TimeZone = TimeZoneHelper.getSystemTimeZone();
63 | }
64 |
65 | public HijriDateTime(int days, int hour, int min, int sec, TimeZone timeZone) {
66 | this(days);
67 | Hour = hour;
68 | Min = min;
69 | Sec = sec;
70 | TimeZone = timeZone;
71 | }
72 |
73 | public HijriDateTime(int unixTimeSeconds, TimeZone timeZone) {
74 |
75 | int offset = TimeZoneHelper.ToSeconds(timeZone);
76 |
77 | DateModel dateModel = DateConverter.UnixToHijri(unixTimeSeconds + offset);
78 | Year = dateModel.year;
79 | Month = dateModel.month;
80 | Day = dateModel.day;
81 | Hour = dateModel.hour;
82 | Min = dateModel.min;
83 | Sec = dateModel.sec;
84 | TimeZone = timeZone;
85 | }
86 |
87 |
88 | public static HijriDateTime Parse(String date) {
89 | int y = Integer.valueOf(date.substring(0, 4));
90 | int m = Integer.valueOf(date.substring(5, 7));
91 | int d = Integer.valueOf(date.substring(8, 10));
92 | return new HijriDateTime(y, m, d);
93 | }
94 |
95 | public static HijriDateTime Parse(String yearMonth, int day) {
96 | int y = Integer.valueOf(yearMonth.substring(0, 4));
97 | int m = Integer.valueOf(yearMonth.substring(5, 7));
98 | return new HijriDateTime(y, m, day);
99 | }
100 |
101 | public static HijriDateTime ParseYearMonth(String yearMonth) {
102 | int y = Integer.valueOf(yearMonth.substring(0, 4));
103 | int m = Integer.valueOf(yearMonth.substring(5, 7));
104 | return new HijriDateTime(y, m, 1);
105 | }
106 |
107 | public static HijriDateTime Now() {
108 | return new HijriDateTime(UnixTimeTools.getCurrentUnixTime(), TimeZoneHelper.getSystemTimeZone());
109 | }
110 |
111 | public DateModel getDate() {
112 | DateModel md = DateConverter.HijriToGregorian(Year, Month, Day);
113 | return new DateModel(md.year, md.month, md.day);
114 | }
115 |
116 | public DateModel getFirstDayOfYear() {
117 | DateModel md = DateConverter.HijriToGregorian(Year, 1, 1);
118 | return new DateModel(md.year, md.month, md.day);
119 | }
120 |
121 | public DateModel getLastDayOfYear() {
122 | DateModel md = DateConverter.HijriToGregorian(Year, 12, DaysInMonth[12] - (!DateConverter.IsHijriLeap(Year) ? 1 : 0));
123 | return new DateModel(md.year, md.month, md.day, 23, 59, 59);
124 | }
125 |
126 | public DateModel getFirstDayOfMonth() {
127 | DateModel md = DateConverter.HijriToGregorian(Year, Month, 1);
128 | return new DateModel(md.year, md.month, md.day);
129 | }
130 |
131 | public DateModel getLastDayOfMonth() {
132 | DateModel md = DateConverter.HijriToGregorian(Year, Month, DaysInMonth[Month] - (Month == 12 && !DateConverter.IsHijriLeap(Year) ? 1 : 0));
133 | return new DateModel(md.year, md.month, md.day, 23, 59, 59);
134 | }
135 |
136 | public DateModel FirstDayOfSeason(Season season) {
137 | DateModel d = getDate();
138 | DateModel mFirstDayOfSeason = new GregorianDateTime(d.year, d.month, d.day).FirstDayOfSeason(season);
139 | HijriDateTime firstDayOfSeason = new HijriDateTime(mFirstDayOfSeason.year, mFirstDayOfSeason.month, mFirstDayOfSeason.day);
140 |
141 | if (firstDayOfSeason.Year == Year) {
142 | if (firstDayOfSeason.Month < 11 || firstDayOfSeason.Month == 11 && firstDayOfSeason.Day <= 15) {
143 | return mFirstDayOfSeason;
144 | }
145 |
146 | getDate().month = getDate().month - 6;
147 | return new HijriDateTime(d.year, d.month, d.day).FirstDayOfSeason(season);
148 | }
149 |
150 |
151 | if (firstDayOfSeason.Year == Year - 1) {
152 | if (firstDayOfSeason.Month == 12 || firstDayOfSeason.Month == 11 && firstDayOfSeason.Day >= 15) {
153 | return mFirstDayOfSeason;
154 | }
155 | }
156 |
157 | getDate().month = getDate().month - (firstDayOfSeason.Year < Year ? 6 : -6);
158 | return new HijriDateTime(d.year, d.month, d.day).FirstDayOfSeason(season);
159 | }
160 |
161 |
162 | public DateModel LastDayOfSeason(Season season) {
163 | DateModel d = FirstDayOfSeason(season);
164 | return new GregorianDateTime(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZone).LastDayOfSeason(season);
165 | }
166 |
167 |
168 | public Season getSeason() {
169 | switch (getDate().month) {
170 | case 1:
171 | case 2:
172 | case 3:
173 | return Season.Winter;
174 | case 4:
175 | case 5:
176 | case 6:
177 | return Season.Spring;
178 | case 7:
179 | case 8:
180 | case 9:
181 | return Season.Summer;
182 | case 10:
183 | case 11:
184 | case 12:
185 | return Season.Autumn;
186 | }
187 | throw new IndexOutOfBoundsException("month is out of bound");
188 | }
189 |
190 |
191 | public DateModel AddYears(int years) {
192 | int y = Year + years;
193 | int m = Month;
194 | int maxd = DaysInMonth[m];
195 | maxd -= (m == 12 && !DateConverter.IsHijriLeap(y) ? 1 : 0);
196 | int d = Day > maxd ? maxd : Day;
197 | return new HijriDateTime(y, m, d).getDate();
198 | }
199 |
200 |
201 | public DateModel AddMonths(int months) {
202 | int m = Month - 1 + months;
203 | int y = Year + (m / 12);
204 | m = (m % 12) + 1;
205 | int maxd = DaysInMonth[m];
206 | maxd -= (m == 12 && !DateConverter.IsHijriLeap(y) ? 1 : 0);
207 | int d = Day > maxd ? maxd : Day;
208 | return new HijriDateTime(y, m, d).getDate();
209 | }
210 |
211 |
212 | public DateModel AddDays(int days) {
213 | return new HijriDateTime(getDays() + days).getDate();
214 | }
215 |
216 |
217 | public JalaliDateTime getJalaliDateTime() {
218 | DateModel d = getDate();
219 | return new JalaliDateTime(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZone);
220 | }
221 |
222 |
223 | public GregorianDateTime getGregorianDateTime() {
224 | DateModel d = getDate();
225 | return new GregorianDateTime(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZone);
226 | }
227 |
228 |
229 | public HijriDateTime getHijriDateTime() {
230 | return this;
231 | }
232 |
233 |
234 | public String getLetters() {
235 | return "";
236 | }
237 |
238 |
239 | public String getMonthLetters() {
240 | return "";
241 | }
242 |
243 |
244 | public String getYearMonthLetters() {
245 | return "";
246 | }
247 |
248 |
249 | public int getYear() {
250 | return Year;
251 | }
252 |
253 |
254 | public int getMonth() {
255 | return Month;
256 | }
257 |
258 |
259 | public int getDay() {
260 | return Day;
261 | }
262 |
263 | @Override
264 | public int getHour() {
265 | return Hour;
266 | }
267 |
268 | @Override
269 | public int getMin() {
270 | return Min;
271 | }
272 |
273 | @Override
274 | public int getSec() {
275 | return Sec;
276 | }
277 |
278 | public int getDays() {
279 | return DateConverter.HijriToDays(Year, Month, Day);
280 | }
281 |
282 | @Override
283 | public int getDaysOfMonth() {
284 | return DaysInMonth[Month] - (Month == 12 & !DateConverter.IsHijriLeap(Year) ? 1 : 0);
285 | }
286 |
287 | public DayOfWeek getDayOfWeek() {
288 | return DayOfWeek.ToDayOfWeek((getDays() + 5) % 7);
289 | }
290 |
291 |
292 | public String getToYearMonth() {
293 | return String.format("%04d/%02d " + TimeZone.getDisplayName(), Year, Month); //tested
294 | }
295 |
296 | public String toString() {
297 | return String.format("%04d/%02d/%02d " + TimeZone.getDisplayName(), Year, Month, Day); //tested
298 | }
299 |
300 | public String toLongString() {
301 | return String.format("%04d/%02d/%02d %02d:%02d:%02d " + TimeZone.getDisplayName(), Year, Month, Day, Hour, Min, Sec);
302 | }
303 |
304 | @Override
305 | public int compareTo(@NonNull HijriDateTime o) {
306 | return CompareTo(o);
307 | }
308 |
309 | public int CompareTo(IDate t2) {
310 | if (t2.getYear() > Year) return -1;
311 | if (t2.getYear() < Year) return 1;
312 | if (t2.getMonth() > Month) return -1;
313 | if (t2.getMonth() < Month) return 1;
314 | if (t2.getDay() > Day) return -1;
315 | return t2.getDay() == Day ? 0 : 1;
316 | }
317 |
318 | public boolean equals(HijriDateTime other) {
319 | return Year == other.Year && Month == other.Month && Day == other.Day;
320 | }
321 |
322 | public boolean equals(Object obj) {
323 | if (null == obj) { // C# :ReferenceEquals(null, obj)
324 |
325 | return false;
326 | }
327 |
328 | return obj instanceof HijriDateTime && equals((HijriDateTime) obj);
329 | }
330 |
331 | public int hashCode() {
332 | int hashCode = Year;
333 | hashCode = (hashCode * 397) ^ Month;
334 | hashCode = (hashCode * 397) ^ Day;
335 | return hashCode;
336 | }
337 |
338 | @Override
339 | public int toUnixTime() {
340 | return DateConverter.HijriToUnix(Year, Month, Day, Hour, Min, Sec) - TimeZoneHelper.ToSeconds(TimeZone);
341 | }
342 | }
343 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/IDate.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | import com.ali.uneversaldatetools.model.DateModel;
4 |
5 | /**
6 | * Created by ali on 9/5/18.
7 | */
8 |
9 | public interface IDate {
10 |
11 | int getYear();
12 |
13 | int getMonth();
14 |
15 | int getDay();
16 |
17 | int getHour();
18 |
19 | int getMin();
20 |
21 | int getSec();
22 |
23 | int getDays();
24 |
25 | int getDaysOfMonth();
26 |
27 | DateModel getDate();
28 |
29 | JalaliDateTime getJalaliDateTime();
30 |
31 | GregorianDateTime getGregorianDateTime();
32 |
33 | HijriDateTime getHijriDateTime();
34 |
35 | DateModel getFirstDayOfYear();
36 |
37 | DateModel getLastDayOfYear();
38 |
39 | DateModel getFirstDayOfMonth();
40 |
41 | DateModel getLastDayOfMonth();
42 |
43 | DateModel FirstDayOfSeason(Season season);
44 |
45 | DateModel LastDayOfSeason(Season season);
46 |
47 | Season getSeason();
48 |
49 | DayOfWeek getDayOfWeek();
50 |
51 | DateModel AddYears(int years);
52 |
53 | DateModel AddMonths(int months);
54 |
55 | DateModel AddDays(int days);
56 |
57 | String getLetters();
58 |
59 | String getMonthLetters();
60 |
61 | String getYearMonthLetters();
62 |
63 | String getToYearMonth();
64 |
65 | int toUnixTime();
66 | }
67 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/JalaliDateTime.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import com.ali.uneversaldatetools.model.DateModel;
6 | import com.ali.uneversaldatetools.tools.UnixTimeTools;
7 |
8 | import java.util.TimeZone;
9 |
10 | /**
11 | * Created by ali on 9/5/18.
12 | */
13 |
14 | public class JalaliDateTime implements IDate, Comparable {
15 |
16 | private int Year;
17 | private int Month;
18 | private int Day;
19 | private int Hour;
20 | private int Min;
21 | private int Sec;
22 | private TimeZone TimeZone;
23 |
24 | static final int[] DaysInMonth = {
25 | 0,
26 | 31,
27 | 31,
28 | 31,
29 | 31,
30 | 31,
31 | 31,
32 | 30,
33 | 30,
34 | 30,
35 | 30,
36 | 30,
37 | 30
38 | };
39 |
40 | public JalaliDateTime(int year, int month, int day) {
41 |
42 | DateValidation.JalaliValidate(year, month, day, 0, 0, 0);
43 |
44 | Year = year;
45 | Month = month;
46 | Day = day;
47 |
48 | TimeZone = TimeZoneHelper.getSystemTimeZone();
49 | }
50 |
51 | public JalaliDateTime(int year, int month, int day, int hour, int min, int sec, TimeZone timeZone) {
52 |
53 | this(year, month, day);
54 | DateValidation.JalaliValidate(year, month, day, hour, min, sec);
55 | Hour = hour;
56 | Min = min;
57 | Sec = sec;
58 | TimeZone = timeZone;
59 | }
60 |
61 | public JalaliDateTime(int days) {
62 | DateModel sd = DateConverter.DaysToJalali(days);
63 |
64 | Year = sd.year;
65 | Month = sd.month;
66 | Day = sd.day;
67 | TimeZone = TimeZoneHelper.getSystemTimeZone();
68 | }
69 |
70 | public JalaliDateTime(int days, int hour, int min, int sec, TimeZone timeZone) {
71 | this(days);
72 | Hour = hour;
73 | Min = min;
74 | Sec = sec;
75 | TimeZone = timeZone;
76 | }
77 |
78 | public JalaliDateTime(int unixTimeSeconds, TimeZone timeZone) {
79 |
80 | int offset = TimeZoneHelper.ToSeconds(timeZone);
81 |
82 | DateModel dateModel = DateConverter.UnixToJalali(unixTimeSeconds + offset);
83 | Year = dateModel.year;
84 | Month = dateModel.month;
85 | Day = dateModel.day;
86 | Hour = dateModel.hour;
87 | Min = dateModel.min;
88 | Sec = dateModel.sec;
89 | TimeZone = timeZone;
90 | }
91 |
92 |
93 | public static JalaliDateTime Parse(String s) {
94 | int y = Integer.valueOf(s.substring(0, 4));
95 | int m = Integer.valueOf(s.substring(5, 7));
96 | int d = Integer.valueOf(s.substring(8, 10));
97 | return new JalaliDateTime(y, m, d);
98 | }
99 |
100 | public static JalaliDateTime Parse(String yearMonth, int day) {
101 | int y = Integer.valueOf(yearMonth.substring(0, 4));
102 | int m = Integer.valueOf(yearMonth.substring(5, 7));
103 | return new JalaliDateTime(y, m, day);
104 | }
105 |
106 | public static JalaliDateTime ParseYearMonth(String s) {
107 | int y = Integer.valueOf(s.substring(0, 4));
108 | int m = Integer.valueOf(s.substring(5, 7));
109 | return new JalaliDateTime(y, m, 1);
110 | }
111 |
112 | public static JalaliDateTime Now() {
113 | return new JalaliDateTime(UnixTimeTools.getCurrentUnixTime(), TimeZoneHelper.getSystemTimeZone());
114 | }
115 |
116 | public DateModel getDate() {
117 | DateModel md = DateConverter.JalaliToGregorian(Year, Month, Day);
118 | return new DateModel(md.year, md.month, md.day);
119 | }
120 |
121 | public DateModel getFirstDayOfYear() {
122 | DateModel md = DateConverter.JalaliToGregorian(Year, 1, 1);
123 | return new DateModel(md.year, md.month, md.day);
124 | }
125 |
126 | public DateModel getLastDayOfYear() {
127 | DateModel md = DateConverter.JalaliToGregorian(Year, 12,
128 | DaysInMonth[12] - (!DateConverter.IsJalaliLeap(Year) ? 1 : 0));
129 | return new DateModel(md.year, md.month, md.day, 23, 59, 59);
130 | }
131 |
132 | public DateModel getFirstDayOfMonth() {
133 | DateModel md = DateConverter.JalaliToGregorian(Year, Month, 1);
134 | return new DateModel(md.year, md.month, md.day);
135 | }
136 |
137 | public DateModel getLastDayOfMonth() {
138 | DateModel md = DateConverter.JalaliToGregorian(Year, Month, DaysInMonth[Month] - (Month == 12 && !DateConverter.IsJalaliLeap(Year) ? 1 : 0));
139 | return new DateModel(md.year, md.month, md.day, 23, 59, 59);
140 | }
141 |
142 | public DateModel FirstDayOfSeason(Season season) {
143 | int month = 1 + (season.getValue() - 1) * 3;
144 | return new JalaliDateTime(Year, month, 1).getDate();
145 | }
146 |
147 | public DateModel LastDayOfSeason(Season season) {
148 | int month = 3 + (season.getValue() - 1) * 3;
149 | int day = DaysInMonth[month] - (month == 12 && !DateConverter.IsJalaliLeap(Year) ? 1 : 0);
150 | DateModel md = DateConverter.JalaliToGregorian(Year, month, day);
151 | return new DateModel(md.year, md.month, md.day, 23, 59, 59);
152 | }
153 |
154 | public Season getSeason() {
155 | switch (Month) {
156 | case 1:
157 | case 2:
158 | case 3:
159 | return Season.Spring;
160 | case 4:
161 | case 5:
162 | case 6:
163 | return Season.Summer;
164 | case 7:
165 | case 8:
166 | case 9:
167 | return Season.Autumn;
168 | case 10:
169 | case 11:
170 | case 12:
171 | return Season.Winter;
172 | }
173 | throw new IndexOutOfBoundsException("season not valid");
174 | }
175 |
176 | public DateModel AddYears(int years) {
177 | int y = Year + years;
178 | int m = Month;
179 | int maxd = DaysInMonth[m];
180 | maxd -= (m == 12 && !DateConverter.IsJalaliLeap(y) ? 1 : 0);
181 | int d = Day > maxd ? maxd : Day;
182 | return new JalaliDateTime(y, m, d).getDate();
183 | }
184 |
185 | public DateModel AddMonths(int months) {
186 | int m = Month - 1 + months;
187 | int y = Year + (m / 12);
188 | m = (m % 12) + 1;
189 | int maxd = DaysInMonth[m];
190 | maxd -= (m == 12 && !DateConverter.IsJalaliLeap(y) ? 1 : 0);
191 | int d = Day > maxd ? maxd : Day;
192 | return new JalaliDateTime(y, m, d).getDate();
193 | }
194 |
195 | public DateModel AddDays(int days) {
196 | return new JalaliDateTime(getDays() + days).getDate();
197 | }
198 |
199 | public JalaliDateTime getJalaliDateTime() {
200 | return this;
201 | }
202 |
203 | public GregorianDateTime getGregorianDateTime() {
204 | DateModel dateModel = getDate();
205 | return new GregorianDateTime(dateModel.year, dateModel.month, dateModel.day, dateModel.hour, dateModel.min, dateModel.sec, TimeZoneHelper.getSystemTimeZone());
206 | }
207 |
208 | public HijriDateTime getHijriDateTime() {
209 | DateModel d = getDate();
210 | return new HijriDateTime(d.year, d.month, d.day, d.hour, d.min, d.sec, TimeZone);
211 | }
212 |
213 | public String getLetters() {
214 | return "";
215 | }
216 |
217 | public String getMonthLetters() {
218 | return "";
219 | }
220 |
221 | public String getYearMonthLetters() {
222 | return "";
223 | }
224 |
225 | public int getYear() {
226 | return Year;
227 | }
228 |
229 | @Override
230 | public int getMonth() {
231 | return Month;
232 | }
233 |
234 | @Override
235 | public int getDay() {
236 | return Day;
237 | }
238 |
239 | @Override
240 | public int getHour() {
241 | return Hour;
242 | }
243 |
244 | @Override
245 | public int getMin() {
246 | return Min;
247 | }
248 |
249 | @Override
250 | public int getSec() {
251 | return Sec;
252 | }
253 |
254 | public int getDays() {
255 | return DateConverter.JalaliToDays(Year, Month, Day);
256 | }
257 |
258 | public DayOfWeek getDayOfWeek() {
259 | return DayOfWeek.ToDayOfWeek((getDays() + 5) % 7);
260 | }
261 |
262 | public int getDaysOfMonth() {
263 | return Month < 7 ? 31 : (Month == 12 & !DateConverter.IsJalaliLeap(Year) ? 29 : 30);
264 | }
265 |
266 | public String getToYearMonth() {
267 | return String.format("%04d/%02d " + TimeZone.getDisplayName(), Year, Month);
268 | }
269 |
270 | public String toString() {
271 | return String.format("%04d/%02d/%02d " + TimeZone.getDisplayName(), Year, Month, Day);
272 | }
273 |
274 | public String toLongString() {
275 | return String.format("%04d/%02d/%02d %02d:%02d:%02d " + TimeZone.getDisplayName(), Year, Month, Day, Hour, Min, Sec);
276 | }
277 |
278 | @Override
279 | public int compareTo(@NonNull JalaliDateTime o) {
280 | return CompareTo(o);
281 | }
282 |
283 | public int CompareTo(IDate t2) {
284 | if (t2.getYear() > Year) return -1;
285 | if (t2.getYear() < Year) return 1;
286 | if (t2.getMonth() > Month) return -1;
287 | if (t2.getMonth() < Month) return 1;
288 | if (t2.getDay() > Day) return -1;
289 | return t2.getDay() == Day ? 0 : 1;
290 | }
291 |
292 | public boolean equals(JalaliDateTime other) {
293 | return Year == other.Year && Month == other.Month && Day == other.Day;
294 | }
295 |
296 | public boolean equals(Object obj) {
297 | if (null == obj) {
298 | return false;
299 | }
300 |
301 | return obj instanceof JalaliDateTime && equals((JalaliDateTime) obj);
302 | }
303 |
304 | public int hashCode() {
305 | int hashCode = Year;
306 | hashCode = (hashCode * 397) ^ Month;
307 | hashCode = (hashCode * 397) ^ Day;
308 | return hashCode;
309 | }
310 |
311 | @Override
312 | public int toUnixTime() {
313 | return DateConverter.JalaliToUnix(Year, Month, Day, Hour, Min, Sec) - TimeZoneHelper.ToSeconds(TimeZone);
314 | }
315 | }
316 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/Season.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | /**
4 | * Created by ali on 9/5/18.
5 | */
6 |
7 | public enum Season {
8 | Spring(1),
9 | Summer(2),
10 | Autumn(3),
11 | Winter(4);
12 |
13 | private final int value;
14 | Season(int value) {
15 | this.value = value;
16 | }
17 |
18 | public int getValue() {
19 | return value;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/SeasonHelper.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | /**
4 | * Created by ali on 9/5/18.
5 | */
6 |
7 | public class SeasonHelper {
8 |
9 | public static String[] GetTitleList()
10 | {
11 | return new String[]
12 | {
13 | "بهار", "تابستان", "پاییز", "زمستان"
14 | };
15 | }
16 |
17 | public static Season GetByTitle(String title)
18 | {
19 | switch (title)
20 | {
21 | case "بهار":
22 | {
23 | return Season.Spring;
24 | }
25 | case "تابستان":
26 | {
27 | return Season.Summer;
28 | }
29 | case "پاییز":
30 | {
31 | return Season.Autumn;
32 | }
33 | case "زمستان":
34 | {
35 | return Season.Winter;
36 | }
37 | default:
38 | {
39 | return Season.Spring;
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/date/TimeZoneHelper.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.date;
2 |
3 | import java.util.Date;
4 | import java.util.TimeZone;
5 |
6 | /**
7 | * Created by ali on 9/30/18.
8 | */
9 |
10 | public class TimeZoneHelper {
11 |
12 | public static TimeZone getSystemTimeZone() {
13 | return TimeZone.getDefault();
14 | }
15 |
16 | public static int getSystemOffsetSeconds() {
17 | return (getSystemTimeZone().getOffset(new Date().getTime()) / 1000 / 60) * 60;
18 | }
19 |
20 | public static int ToSeconds(TimeZone timeZone){
21 | return (timeZone.getOffset(new Date().getTime()) / 1000 / 60) * 60;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/datePicker/CalenderViewFragment.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.datePicker;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.GridLayout;
13 |
14 | import com.ali.uneversaldatetools.R;
15 | import com.ali.uneversaldatetools.model.Month;
16 |
17 | /**
18 | * Created by ali on 9/12/18.
19 | */
20 |
21 |
22 | public class CalenderViewFragment extends Fragment {
23 |
24 | private Month mMonth;
25 | private View cView;
26 | private CalenderFragmentInterface mInterface;
27 | private int mIndex;
28 |
29 | /**
30 | * @apiNote Do not use it
31 | */
32 | public CalenderViewFragment() {
33 | throw new RuntimeException("do not use this constructor");
34 | }
35 |
36 | @SuppressLint("ValidFragment")
37 | public CalenderViewFragment(Month month, int index, CalenderFragmentInterface mInterface) {
38 | this.mMonth = month;
39 | this.mInterface = mInterface;
40 | mIndex = index;
41 | Log.d("swipe", "const(" + String.valueOf(index) + ")");
42 | }
43 |
44 | @SuppressLint("ResourceAsColor")
45 | @Nullable
46 | @Override
47 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
48 |
49 | cView = inflater.inflate(R.layout.item_month_view, null);
50 | Log.d("swipe", "createView(" + String.valueOf(mIndex) + ")");
51 | Render();
52 | return cView;
53 | }
54 |
55 | public void Render() {
56 | if (cView == null)
57 | throw new RuntimeException("Render called before onCreateView in index: " + mIndex);
58 | Log.d("swipe", "render(" + String.valueOf(mIndex) + ")");
59 | GridLayout gridLayout = cView.findViewById(R.id.grid_layout_days);
60 | gridLayout.removeAllViews();
61 | DaysViewGenerator daysViewGenerator = new DaysViewGenerator(getActivity());
62 |
63 | //add empties
64 | for (int i = 0; mMonth.getStartAt().getValue() > i; i++)
65 | gridLayout.addView(daysViewGenerator.getEmptyView());
66 |
67 | //add days
68 | for (int i = 1; mMonth.getDaysCount() >= i; i++) {
69 | if (i == mInterface.selectedDayProvider())
70 | AddView(gridLayout, daysViewGenerator.getSelectedView(i));
71 | else if (i == mInterface.currentDayProvider() & mInterface.currentMonthProvider() == mIndex + 1) {
72 | AddView(gridLayout, daysViewGenerator.getTodayView(i));
73 | } else {
74 | AddView(gridLayout, daysViewGenerator.getNormalView(i));
75 | }
76 | }
77 | }
78 |
79 | public void AddView(GridLayout gridLayout, View view) {
80 | gridLayout.addView(view);
81 |
82 | view.setOnClickListener(v -> {
83 | mInterface.onDaySelectListener((int) v.getTag(), mMonth.getPos());
84 | Render();
85 | });
86 | }
87 |
88 | public interface CalenderFragmentInterface {
89 |
90 | void onDaySelectListener(int day, int monthIndex);
91 |
92 | int selectedDayProvider();
93 |
94 | int currentMonthProvider();
95 |
96 | int currentDayProvider();
97 | }
98 |
99 | public void setMonth(Month month) {
100 | mMonth = month;
101 | try {
102 | Render();
103 | } catch (RuntimeException e) {
104 | if (e.getMessage().equals("Render called before onCreateView in index: "))
105 | throw e;
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/datePicker/DaysViewGenerator.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.datePicker;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.ali.uneversaldatetools.R;
10 | import com.ali.uneversaldatetools.tools.StringGenerator;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | /**
16 | * Created by ali on 9/9/18.
17 | */
18 |
19 | class DaysViewGenerator {
20 |
21 | private Context mActivity;
22 | private LayoutInflater mInflator;
23 |
24 | DaysViewGenerator(Context context) {
25 | mActivity = context;
26 | mInflator = LayoutInflater.from(context);
27 | }
28 |
29 | View getEmptyView() {
30 | return mInflator.inflate(R.layout.item_day_empty, null);
31 | }
32 |
33 | View getNormalView(int num) {
34 | ViewGroup root = (ViewGroup) mInflator.inflate(R.layout.item_day_normal, null);
35 | TextView day = (TextView) ((ViewGroup) root.getChildAt(0)).getChildAt(0);
36 | day.setText(StringGenerator.NumberToString(mActivity.getResources(), num));
37 | root.setTag(num);
38 | return root;
39 | }
40 |
41 | View getSelectedView(int num) {
42 |
43 | ViewGroup root = (ViewGroup) mInflator.inflate(R.layout.item_day_selected, null);
44 | TextView day = (TextView) ((ViewGroup) root.getChildAt(0)).getChildAt(1);
45 | day.setText(StringGenerator.NumberToString(mActivity.getResources(), num));
46 | root.setTag(num);
47 | return root;
48 | }
49 |
50 | View getTodayView(int num) {
51 | ViewGroup root = (ViewGroup) mInflator.inflate(R.layout.item_day_today, null);
52 | TextView day = (TextView) ((ViewGroup) root.getChildAt(0)).getChildAt(1);
53 | day.setText(StringGenerator.NumberToString(mActivity.getResources(), num));
54 | root.setTag(num);
55 | return root;
56 | }
57 |
58 | List getDayOfWeek() {
59 |
60 | List views = new ArrayList<>();
61 |
62 | for (String i : mActivity.getResources().getStringArray(R.array.week_days_one_char)) {
63 | ViewGroup root = (ViewGroup) mInflator.inflate(R.layout.item_day_normal, null);
64 | TextView day = (TextView) ((ViewGroup) root.getChildAt(0)).getChildAt(0);
65 | day.setTextColor(mActivity.getResources().getColor(R.color.gray));
66 | day.setText(i);
67 | views.add(root);
68 | }
69 |
70 | return views;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/datePicker/UDatePicker.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.datePicker;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.view.ViewPager;
9 | import android.util.AttributeSet;
10 | import android.util.Log;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.widget.AbsListView;
14 | import android.widget.ArrayAdapter;
15 | import android.widget.FrameLayout;
16 | import android.widget.ImageView;
17 | import android.widget.LinearLayout;
18 | import android.widget.ListView;
19 | import android.widget.TextView;
20 |
21 | import com.ali.uneversaldatetools.R;
22 | import com.ali.uneversaldatetools.date.Calendar;
23 | import com.ali.uneversaldatetools.date.DateSystem;
24 | import com.ali.uneversaldatetools.date.TimeZoneHelper;
25 | import com.ali.uneversaldatetools.model.Month;
26 | import com.ali.uneversaldatetools.tools.Convert;
27 | import com.ali.uneversaldatetools.tools.ExpandAndCollapseAnimation;
28 | import com.ali.uneversaldatetools.tools.StringGenerator;
29 | import com.ali.uneversaldatetools.tools.UnixTimeTools;
30 |
31 | import java.util.ArrayList;
32 | import java.util.List;
33 |
34 | import static android.support.v4.view.ViewPager.SCROLL_STATE_IDLE;
35 |
36 | /**
37 | * Created by ali on 9/5/18.
38 | */
39 |
40 | public class UDatePicker
41 | extends
42 | FrameLayout
43 | implements
44 | CalenderViewFragment.CalenderFragmentInterface,
45 | ViewPager.OnPageChangeListener {
46 |
47 | private OnDateChangedListener listener;
48 | private Context mContext;
49 | private ViewPagerAdapter mViewPagerAdapter;
50 | private ViewPager mViewPager;
51 | private TextView topbarMonthText;
52 | private int currentSelectedYear = 0;
53 |
54 | private DateSystem mDateSystem; // current selected date
55 |
56 | public UDatePicker(Context context) {
57 | super(context);
58 | Init(context);
59 | }
60 |
61 | public UDatePicker(Context context, @Nullable AttributeSet attrs) {
62 | super(context, attrs);
63 | Init(context);
64 | }
65 |
66 | public UDatePicker(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
67 | super(context, attrs, defStyleAttr);
68 | Init(context);
69 | }
70 |
71 | private void Init(Context context) {
72 |
73 | LayoutInflater mInflater = LayoutInflater.from(context);
74 |
75 | this.mContext = context;
76 |
77 | View dayPickerView = mInflater.inflate(R.layout.u_date_picker_days_month, null);
78 | addView(dayPickerView);
79 |
80 | View yearPickerView = mInflater.inflate(R.layout.u_date_picker_year, null);
81 | addView(yearPickerView);
82 |
83 | }
84 |
85 | public void ShowDatePicker(FragmentManager appCompatActivity, @NonNull DateSystem defaultDate) {
86 | mDateSystem = defaultDate;
87 | SetupDayPicker(appCompatActivity, LoadMonths(mDateSystem));
88 | SetupYearPicker(mDateSystem.getYear());
89 | }
90 |
91 | public void ShowDatePicker(FragmentManager appCompatActivity, Calendar calendar) {
92 | DateSystem defaultDate = new DateSystem(UnixTimeTools.getCurrentUnixTime(), TimeZoneHelper.getSystemTimeZone(), calendar); // now
93 | ShowDatePicker(appCompatActivity, defaultDate);
94 | }
95 |
96 | @SuppressLint("ClickableViewAccessibility")
97 | private void SetupDayPicker(FragmentManager appCompatActivity, ArrayList months) {
98 | this.getLayoutParams().height = Convert.DpToPixel(350);
99 | this.getLayoutParams().width = Convert.DpToPixel(300);
100 | requestLayout();
101 |
102 | SetupDayOfWeek();
103 | SetupArrowKeys();
104 |
105 | topbarMonthText = findViewById(R.id.text_top_bar_month);
106 | mViewPager = findViewById(R.id.pager_swipe_layout);
107 |
108 | mViewPager.addOnPageChangeListener(this);
109 |
110 | topbarMonthText.setText(StringGenerator.Month(
111 | getResources(),
112 | mDateSystem.getMonth(),
113 | mDateSystem.getCalendar())
114 | );
115 |
116 | mViewPagerAdapter = new ViewPagerAdapter(appCompatActivity);
117 | for (Month month : months) {
118 | mViewPagerAdapter.AddFragment(new CalenderViewFragment(month, months.indexOf(month), this));
119 | }
120 | //for making viewpager swipe circle
121 | mViewPagerAdapter.AddFragment(new CalenderViewFragment(months.get(0), months.indexOf(months.get(0)), this));
122 | mViewPagerAdapter.AddFragment(new CalenderViewFragment(months.get(1), months.indexOf(months.get(1)), this));
123 |
124 |
125 | mViewPager.setAdapter(mViewPagerAdapter);
126 | mViewPager.setCurrentItem(mDateSystem.getMonth() - 1, false);
127 | }
128 |
129 | private void SetupYearPicker(int selectedYear) {
130 |
131 | LinearLayout topbarMonth = findViewById(R.id.linear_top_bar_month);
132 | LinearLayout topbarYear = findViewById(R.id.linear_top_bar_year);
133 | TextView topbarYearText = findViewById(R.id.text_top_bar_year);
134 | TextView topbarMonthTitle = findViewById(R.id.text_top_bar_month_title);
135 | TextView topbarYearTitle = findViewById(R.id.text_top_bar_year_title);
136 | ListView yearListview = findViewById(R.id.list_year_picker);
137 | ImageView arrowLeft = findViewById(R.id.img_calender_arrow_left);
138 | ImageView arrowRight = findViewById(R.id.img_calender_arrow_right);
139 | View yearPickerView = this.getChildAt(1);
140 |
141 |
142 | //top bar init
143 | topbarYearText.setText(StringGenerator.NumberToString(mContext.getResources(), selectedYear));
144 |
145 | // visible/invisible + effect
146 |
147 | topbarMonth.setAlpha(1);
148 | topbarYear.setAlpha((float) 0.6);
149 | topbarMonth.setOnClickListener(v -> {
150 | if (yearPickerView.getVisibility() == View.GONE) return;
151 |
152 | arrowLeft.animate().alpha(1).setDuration(200).start();
153 | arrowRight.animate().alpha(1).setDuration(200).start();
154 | topbarMonth.animate().alpha(1).setDuration(200).start();
155 | topbarYear.animate().alpha((float) 0.6).setDuration(200).start();
156 | postDelayed(() -> yearPickerView.setVisibility(GONE), 300);
157 | yearPickerView.animate().alpha(0).setDuration(300).start();
158 | ExpandAndCollapseAnimation.Collapse(topbarYearTitle);
159 | ExpandAndCollapseAnimation.Expand(topbarMonthTitle);
160 |
161 | if (currentSelectedYear == mDateSystem.getYear()) return; //for optimize
162 |
163 | //refresh viewPager
164 | mDateSystem = new DateSystem(
165 | currentSelectedYear,
166 | mDateSystem.getMonth(),
167 | mDateSystem.getDay(),
168 | mDateSystem.getCalendar());
169 |
170 | List months = LoadMonths(mDateSystem);
171 | for (Month month : months) {
172 | ((CalenderViewFragment) mViewPagerAdapter.getItem(months.indexOf(month))).setMonth(month);
173 | }
174 | ((CalenderViewFragment) mViewPagerAdapter.getItem(12)).setMonth(months.get(0));
175 | ((CalenderViewFragment) mViewPagerAdapter.getItem(13)).setMonth(months.get(1));
176 | mViewPagerAdapter.notifyDataSetChanged();
177 | });
178 | topbarYear.setOnClickListener(v -> {
179 | if (yearPickerView.getVisibility() == VISIBLE) return;
180 |
181 | arrowLeft.animate().alpha((float) 0.6).setDuration(200).start();
182 | arrowRight.animate().alpha((float) 0.6).setDuration(200).start();
183 | topbarMonth.animate().alpha((float) 0.6).setDuration(200).start();
184 | topbarYear.animate().alpha(1).setDuration(200).start();
185 | yearPickerView.setVisibility(VISIBLE);
186 | yearPickerView.animate().alpha(1).setDuration(300).start();
187 | ExpandAndCollapseAnimation.Collapse(topbarMonthTitle);
188 | ExpandAndCollapseAnimation.Expand(topbarYearTitle);
189 | });
190 |
191 |
192 | //listView
193 | ArrayAdapter adapter = new ArrayAdapter<>(mContext, R.layout.item_year, R.id.text_year_item, LoadYears());
194 | yearListview.setAdapter(adapter);
195 | yearListview.setSelection(selectedYear - 3);
196 | yearListview.setOnItemClickListener((parent, view, position, id) -> {
197 |
198 | Log.d("selectedCO", String.valueOf(position) + " " + String.valueOf(currentSelectedYear));
199 | if (position != currentSelectedYear) return; //make on selected items un clickable
200 |
201 | topbarYearText.setText(StringGenerator.NumberToString(mContext.getResources(), position));
202 | yearListview.setSelection(position - 3);
203 |
204 | topbarMonth.setAlpha(1);
205 | topbarYear.setAlpha((float) 0.6);
206 | postDelayed(() -> yearPickerView.setVisibility(GONE), 300);
207 | yearPickerView.animate().alpha(0).setDuration(300).start();
208 | ExpandAndCollapseAnimation.Collapse(topbarYearTitle);
209 | ExpandAndCollapseAnimation.Expand(topbarMonthTitle);
210 |
211 | if (position == mDateSystem.getYear()) return; //for optimize
212 |
213 | //refresh viewPager
214 | mDateSystem = new DateSystem(
215 | position,
216 | mDateSystem.getMonth(),
217 | mDateSystem.getDay(),
218 | mDateSystem.getCalendar());
219 |
220 | List months = LoadMonths(mDateSystem);
221 | for (Month month : months) {
222 | ((CalenderViewFragment) mViewPagerAdapter.getItem(months.indexOf(month))).setMonth(month);
223 | }
224 | ((CalenderViewFragment) mViewPagerAdapter.getItem(12)).setMonth(months.get(0));
225 | ((CalenderViewFragment) mViewPagerAdapter.getItem(13)).setMonth(months.get(1));
226 | mViewPagerAdapter.notifyDataSetChanged();
227 | });
228 |
229 | //new
230 |
231 | yearListview.setOnScrollListener(new AbsListView.OnScrollListener() {
232 | @Override
233 | public void onScrollStateChanged(AbsListView view, int scrollState) {
234 |
235 | if (scrollState == SCROLL_STATE_IDLE) {
236 | yearListview.setSelection(currentSelectedYear - 3);
237 | }
238 | }
239 |
240 | @Override
241 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
242 | if (currentSelectedYear != firstVisibleItem) {
243 | Log.d("selectedCO", String.valueOf(firstVisibleItem + 3));
244 | topbarYearText.setText(StringGenerator.NumberToString(mContext.getResources(), firstVisibleItem + 3));
245 |
246 | currentSelectedYear = firstVisibleItem + 3;
247 | }
248 | }
249 | });
250 | }
251 |
252 | public void setOnDateSelected(OnDateChangedListener listener) {
253 | this.listener = listener;
254 | }
255 |
256 | public interface OnDateChangedListener {
257 | void onDateChange(@Nullable DateSystem dateSystem, @Nullable long unixTime);
258 | }
259 |
260 | /**
261 | * @return selected date in selected calender
262 | * or null if selected day is 31 but this month have no 31
263 | * you can show message like "plz select day"
264 | */
265 | @Nullable
266 | public DateSystem getSelectedDate() {
267 | DateSystem dateSystem;
268 | if (mDateSystem.getMonth() == 13)
269 | dateSystem = new DateSystem(mDateSystem.getYear(), 1, mDateSystem.getDay(), mDateSystem.getCalendar());
270 | else
271 | dateSystem = mDateSystem;
272 |
273 | if (LoadMonths(dateSystem).get(dateSystem.getMonth() - 1).getDaysCount() >= dateSystem.getDay())
274 | return dateSystem;
275 | else return null;// when selected day is 31 but month have no 31
276 | }
277 |
278 | /**
279 | * @return unix time (seconds from 1970/1/1 in UTC + 00:00)
280 | * or null if selected day is 31 but this month have no 31
281 | * you can show message like "plz select day"
282 | */
283 | @Nullable
284 | public Integer getSelectedUnixTime() {
285 | DateSystem dateSystem = getSelectedDate();
286 | if (dateSystem == null) return null;
287 | else return dateSystem.toUnixTime();
288 | }
289 |
290 | private void SetupDayOfWeek() {
291 | LinearLayout daysOfWeek = findViewById(R.id.linear_day_of_week);
292 |
293 | for (View view : new DaysViewGenerator(mContext).getDayOfWeek()) {
294 | daysOfWeek.addView(view);
295 | }
296 | }
297 |
298 | private void SetupArrowKeys() {
299 |
300 | ImageView arrowLeft = findViewById(R.id.img_calender_arrow_left);
301 | ImageView arrowRight = findViewById(R.id.img_calender_arrow_right);
302 |
303 | arrowLeft.setOnClickListener(v -> {
304 | //disable clicks when year picker is visible
305 | if (this.getChildAt(1).getVisibility() == VISIBLE) return;
306 | mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
307 | });
308 |
309 | arrowRight.setOnClickListener(v -> {
310 | //disable clicks when year picker is visible
311 | if (this.getChildAt(1).getVisibility() == VISIBLE) return;
312 | mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1);
313 | });
314 | }
315 |
316 | private ArrayList LoadMonths(final DateSystem date) {
317 |
318 | ArrayList list = new ArrayList<>();
319 | int year = date.getYear();
320 | Calendar calendar = date.getCalendar();
321 |
322 | for (int i = 1; i <= 12; i++) {
323 |
324 | DateSystem dateLoop = new DateSystem(year, i, 1, calendar);// 1 means first day of month
325 |
326 | Month month = new Month(
327 | i,
328 | StringGenerator.Month(mContext.getResources(), i, calendar),
329 | dateLoop.getDaysOfMonth(),
330 | dateLoop.getDayOfWeek()
331 | );
332 | list.add(month);
333 | }
334 | return list;
335 | }
336 |
337 | private List LoadYears() {
338 | List years = new ArrayList<>();
339 | for (int i = 0; i <= 3000; i++) {
340 | years.add(StringGenerator.NumberToString(mContext.getResources(), i));
341 | }
342 | return years;
343 | }
344 |
345 |
346 | //fragment interface implement
347 | @Override
348 | public void onDaySelectListener(int day, int monthPos) {
349 | mDateSystem = new DateSystem(
350 | mDateSystem.getYear(),
351 | mDateSystem.getMonth(),
352 | day,
353 | mDateSystem.getCalendar()
354 | );
355 |
356 | //this part is because last and next viewpager views render before scroll
357 | try {
358 | try {
359 | ((CalenderViewFragment) mViewPagerAdapter.getItem(mDateSystem.getMonth() - 2)).Render();
360 | } catch (RuntimeException e) {
361 | Log.d("something bad happened", e.getMessage());
362 | }
363 |
364 | } catch (ArrayIndexOutOfBoundsException e) {
365 | //whe we are in first pos (have no last pos)
366 | }
367 |
368 | try {
369 | try {
370 | ((CalenderViewFragment) mViewPagerAdapter.getItem(mDateSystem.getMonth())).Render();
371 | } catch (RuntimeException e) {
372 | Log.d("something bad happened", e.getMessage());
373 | }
374 | } catch (IndexOutOfBoundsException e) {
375 | //whe we are in last pos (have no next pos)
376 | }
377 |
378 | if (listener != null) {
379 | DateSystem dateSystem = new DateSystem(mDateSystem.getYear(), monthPos, day, mDateSystem.getCalendar());
380 | listener.onDateChange(dateSystem, dateSystem.toUnixTime());
381 | }
382 | }
383 |
384 | @Override
385 | public int selectedDayProvider() {
386 | return mDateSystem.getDay();
387 | }
388 |
389 | @Override
390 | public int currentMonthProvider() {
391 | return new DateSystem(UnixTimeTools.getCurrentUnixTime(), TimeZoneHelper.getSystemTimeZone(), mDateSystem.getCalendar()).getMonth();
392 | }
393 |
394 | @Override
395 | public int currentDayProvider() {
396 | return new DateSystem(UnixTimeTools.getCurrentUnixTime(), TimeZoneHelper.getSystemTimeZone(), mDateSystem.getCalendar()).getDay();
397 | }
398 |
399 |
400 | //view pager listener
401 | @Override
402 | public void onPageSelected(int position) {
403 | Log.d("swipe", "select(" + String.valueOf(position) + ")");
404 |
405 | topbarMonthText.setText(StringGenerator.Month(
406 | mContext.getResources(),
407 | getMonth(),
408 | mDateSystem.getCalendar()));
409 |
410 |
411 | mDateSystem = new DateSystem(
412 | mDateSystem.getYear(),
413 | position + 1,
414 | mDateSystem.getDay(),
415 | mDateSystem.getCalendar());
416 | }
417 |
418 | @Override
419 | public void onPageScrollStateChanged(int state) {
420 |
421 | if (state == SCROLL_STATE_IDLE) {
422 | //on animation stop
423 | if (mViewPager.getCurrentItem() == 13) {
424 | mViewPager.setCurrentItem(1, false);
425 | } else if (mViewPager.getCurrentItem() == 0) {
426 | mViewPager.setCurrentItem(12, false);
427 | }
428 | }
429 | }
430 |
431 | @Override
432 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {/*ignore*/}
433 |
434 |
435 | private int getMonth() {
436 | int current = mViewPager.getCurrentItem() + 1;
437 | if (current > 12) {
438 | current -= 12;
439 | }
440 | if (current < 0)
441 | throw new RuntimeException("current is less then 0: " + current);
442 | return current;
443 | }
444 | }
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/datePicker/ViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.datePicker;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | class ViewPagerAdapter extends FragmentPagerAdapter {
11 |
12 | private List _mFragmentList = new ArrayList<>();
13 |
14 | ViewPagerAdapter(FragmentManager fm) {
15 | super(fm);
16 | }
17 |
18 | @Override
19 | public Fragment getItem(int position) {
20 | return _mFragmentList.get(position);
21 | }
22 |
23 | @Override
24 | public int getCount() {
25 | return _mFragmentList.size();
26 | }
27 |
28 |
29 | void AddFragment(Fragment fragment) {
30 | _mFragmentList.add(fragment);
31 | }
32 | }
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/model/DateModel.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.model;
2 |
3 | /**
4 | * Created by ali on 9/5/18.
5 | */
6 |
7 | public class DateModel {
8 |
9 | public int year;
10 | public int month;
11 | public int day;
12 | public int hour;
13 | public int min;
14 | public int sec;
15 |
16 | public DateModel(){}
17 |
18 | public DateModel(int year, int month, int day) {
19 | this.year = year;
20 | this.month = month;
21 | this.day = day;
22 | }
23 |
24 | public DateModel(int year, int month, int day, int hour, int min, int sec) {
25 | this(year, month, day);
26 | this.hour = hour;
27 | this.min = min;
28 | this.sec = sec;
29 | }
30 | }
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/model/Month.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.model;
2 |
3 | import com.ali.uneversaldatetools.date.DayOfWeek;
4 |
5 | /**
6 | * Created by ali on 9/9/18.
7 | */
8 |
9 | public class Month {
10 |
11 | private int pos; // 1 -> 12
12 | private String name;
13 | private int daysCount; //28 , 29 , 30 , 31
14 | private DayOfWeek startAt;
15 |
16 | public Month(int pos, String name, int daysCount, DayOfWeek startAt) {
17 | this.pos = pos;
18 | this.name = name;
19 | this.daysCount = daysCount;
20 | this.startAt = startAt;
21 | }
22 |
23 | public int getPos() {
24 | return pos;
25 | }
26 |
27 | public String getName() {
28 | return name;
29 | }
30 |
31 | public int getDaysCount() {
32 | return daysCount;
33 | }
34 |
35 | public DayOfWeek getStartAt() {
36 | return startAt;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/tools/Convert.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.tools;
2 |
3 | import android.content.res.Resources;
4 | import android.util.DisplayMetrics;
5 |
6 | /**
7 | * Created by ali on 8/11/18.
8 | */
9 |
10 | public class Convert {
11 |
12 | public static int PixelsToDp(float px) {
13 | DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
14 | float dp = px / (metrics.densityDpi / 160f);
15 | return Math.round(dp);
16 | }
17 |
18 | public static int DpToPixel(float dp) {
19 | DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
20 | float px = dp * (metrics.densityDpi / 160f);
21 | return Math.round(px);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/tools/ExpandAndCollapseAnimation.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.tools;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 | import android.view.animation.Animation;
6 | import android.view.animation.Transformation;
7 |
8 | /**
9 | * Created by x1 carbon on 3/14/2018.
10 | */
11 |
12 | public class ExpandAndCollapseAnimation {
13 |
14 | public static void Expand(final View v) {
15 | //if (v.getVisibility() == View.VISIBLE) return;
16 | v.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
17 | final int targetHeight = v.getMeasuredHeight();
18 |
19 | v.getLayoutParams().height = 1;
20 | v.setVisibility(View.VISIBLE);
21 | Animation a = new Animation() {
22 | @Override
23 | protected void applyTransformation(float interpolatedTime, Transformation t) {
24 | v.getLayoutParams().height = interpolatedTime == 1
25 | ? ViewGroup.LayoutParams.WRAP_CONTENT
26 | : (int) (targetHeight * interpolatedTime);
27 | v.requestLayout();
28 | }
29 |
30 | @Override
31 | public boolean willChangeBounds() {
32 | return true;
33 | }
34 | };
35 | a.setDuration(200);
36 | v.startAnimation(a);
37 | }
38 |
39 | public static void Collapse(final View v) {
40 | //if (v.getVisibility() == View.GONE) return;
41 | final int initialHeight = v.getMeasuredHeight();
42 |
43 | Animation a = new Animation() {
44 | @Override
45 | protected void applyTransformation(float interpolatedTime, Transformation t) {
46 | if (interpolatedTime == 1) {
47 | v.setVisibility(View.GONE);
48 | } else {
49 | v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
50 | v.requestLayout();
51 | }
52 | }
53 |
54 | @Override
55 | public boolean willChangeBounds() {
56 | return true;
57 | }
58 | };
59 | a.setDuration(200);
60 | v.startAnimation(a);
61 | }
62 | }
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/tools/StringGenerator.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.tools;
2 |
3 | import android.content.res.Resources;
4 |
5 | import com.ali.uneversaldatetools.R;
6 | import com.ali.uneversaldatetools.date.Calendar;
7 |
8 | /**
9 | * Created by ali on 9/8/18.
10 | */
11 |
12 | public class StringGenerator {
13 |
14 | public static String NumberToString(Resources resources, int number) {
15 | String numberStr = String.valueOf(number);
16 | String[] nums = resources.getStringArray(R.array.nums);
17 | numberStr = numberStr.replace("0", nums[0]);
18 | numberStr = numberStr.replace("1", nums[1]);
19 | numberStr = numberStr.replace("2", nums[2]);
20 | numberStr = numberStr.replace("3", nums[3]);
21 | numberStr = numberStr.replace("4", nums[4]);
22 | numberStr = numberStr.replace("5", nums[5]);
23 | numberStr = numberStr.replace("6", nums[6]);
24 | numberStr = numberStr.replace("7", nums[7]);
25 | numberStr = numberStr.replace("8", nums[8]);
26 | numberStr = numberStr.replace("9", nums[9]);
27 | return numberStr;
28 | }
29 |
30 | public static String Month(Resources resources, int index, Calendar calendar) {
31 |
32 | switch (calendar) {
33 | case Gregorian:
34 | return resources.getStringArray(R.array.gregorian_months)[index-1];
35 | case Jalali:
36 | return resources.getStringArray(R.array.jalali_months)[index-1];
37 | case Hijri:
38 | return resources.getStringArray(R.array.hijri_month)[index-1];
39 | default:
40 | throw new IllegalArgumentException("calender not valid");
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/java/com/ali/uneversaldatetools/tools/UnixTimeTools.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools.tools;
2 |
3 | /**
4 | * Created by ali on 9/11/18.
5 | */
6 |
7 | public class UnixTimeTools {
8 |
9 | public static int getCurrentUnixTime() {
10 | return (int) (System.currentTimeMillis() / 1000L); //toSec
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/drawable/arro_left.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/drawable/circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/drawable/counter_left.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/dialog_u_date_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
18 |
19 |
25 |
26 |
32 |
33 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/item_day_empty.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/item_day_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/item_day_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
25 |
26 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/item_day_today.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/item_month_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/item_year.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/u_date_picker_days_month.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
23 |
24 |
25 |
32 |
33 |
41 |
42 |
48 |
49 |
50 |
51 |
56 |
57 |
64 |
65 |
73 |
74 |
80 |
81 |
82 |
83 |
92 |
93 |
94 |
95 |
101 |
102 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/layout/u_date_picker_year.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
22 |
23 |
24 |
31 |
32 |
37 |
38 |
41 |
42 |
48 |
49 |
50 |
51 |
52 |
56 |
57 |
62 |
63 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/values-fa/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | UneversalDateTools
4 |
5 | fa
6 |
7 | ماه
8 | سال
9 | انتخاب
10 | بازگشت
11 |
12 |
13 | فروردین
14 | اردیبهشت
15 | خرداد
16 | تیر
17 | مرداد
18 | شهریور
19 | مهر
20 | آبان
21 | آذر
22 | دی
23 | بهمن
24 | اسفند
25 |
26 |
27 |
28 | ژانویه
29 | فوریه
30 | مارس
31 | آوریل
32 | مه
33 | ژوئن
34 | ژولای
35 | اوت
36 | سپتامبر
37 | اکتبر
38 | نوامبر
39 | دسامبر
40 |
41 |
42 |
43 | محرم
44 | صفر
45 | ربیعالاول
46 | ربیعالثانی
47 | جمادیالاول
48 | جمادیالثانی
49 | رجب
50 | شعبان
51 | رمضان
52 | شوال
53 | ذیقعده
54 | ذیحجه
55 |
56 |
57 |
58 |
59 | شنبه
60 | یکشنبه
61 | دوشنبه
62 | سه شنبه
63 | چهارشنبه
64 | پنجشنبه
65 | جمعه
66 |
67 |
68 |
69 | ش
70 | ی
71 | د
72 | س
73 | چ
74 | پ
75 | ج
76 |
77 |
78 |
79 |
80 | ۰
81 | ۱
82 | ۲
83 | ۳
84 | ۴
85 | ۵
86 | ۶
87 | ۷
88 | ۸
89 | ۹
90 |
91 |
92 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008A8A
4 | #898989
5 | #3b3b3b
6 | #e7e7e7
7 | #000
8 | #8fe7e7e7
9 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40dp
4 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | UneversalDateTools
4 |
5 | en
6 |
7 | month
8 | year
9 | select
10 | cancel
11 |
12 |
13 | Farvardin
14 | Ordibehesht
15 | Khordad
16 | Tir
17 | Mordad
18 | Shahrivar
19 | Mehr
20 | Aban
21 | Azar
22 | Dey
23 | Bahman
24 | Esfand
25 |
26 |
27 |
28 | January
29 | February
30 | March
31 | April
32 | May
33 | June
34 | July
35 | August
36 | September
37 | October
38 | November
39 | December
40 |
41 |
42 |
43 | Muharram
44 | Safar
45 | Rabi al-awwal
46 | Rabi al-thani
47 | J al-awwal
48 | J al-thani
49 | Rajab
50 | Shaban
51 | Ramadan
52 | Shawwal
53 | Dhu al-Qidah
54 | Dhu al-hijjah
55 |
56 |
57 |
58 |
59 | Saturday
60 | SunDay
61 | Monday
62 | Tuesday
63 | Wednesday
64 | Thursday
65 | Friday
66 |
67 |
68 |
69 | S
70 | S
71 | M
72 | T
73 | W
74 | T
75 | F
76 |
77 |
78 |
79 |
80 | 0
81 | 1
82 | 2
83 | 3
84 | 4
85 | 5
86 | 6
87 | 7
88 | 8
89 | 9
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/uneversaldatetools/src/test/java/com/ali/uneversaldatetools/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ali.uneversaldatetools;
2 |
3 | import com.ali.uneversaldatetools.date.DateConverter;
4 | import com.ali.uneversaldatetools.date.GregorianDateTime;
5 | import com.ali.uneversaldatetools.date.HijriDateTime;
6 | import com.ali.uneversaldatetools.date.JalaliDateTime;
7 | import com.ali.uneversaldatetools.date.TimeZoneHelper;
8 | import com.ali.uneversaldatetools.model.DateModel;
9 | import com.ali.uneversaldatetools.tools.UnixTimeTools;
10 |
11 | import org.junit.Assert;
12 | import org.junit.Test;
13 |
14 | import java.util.Date;
15 |
16 | /**
17 | * Example local unit test, which will execute on the development machine (host).
18 | *
19 | * @see Testing documentation
20 | */
21 | public class ExampleUnitTest {
22 |
23 | @Test
24 | public void ToStringTest() {
25 | JalaliDateTime jTime = new JalaliDateTime(1377, 1, 27);
26 | Log(jTime.toString());
27 | Log(jTime.toLongString());
28 | Log("---");
29 | HijriDateTime hTime = new HijriDateTime(1440, 1, 27);
30 | Log(hTime.toString());
31 | Log(hTime.toLongString());
32 | Log("---");
33 | GregorianDateTime gTime = new GregorianDateTime(2002, 1, 27);
34 | Log(gTime.toString());
35 | Log(gTime.toLongString());
36 | }
37 |
38 | @Test
39 | public void UnixTest() {
40 | int unixTime = UnixTimeTools.getCurrentUnixTime();
41 |
42 | Log(unixTime);
43 | DateModel dateModel = DateConverter.UnixToJalali(unixTime);
44 | Log(dateModel.year);
45 | Log(dateModel.month);
46 | Log(dateModel.day);
47 | Log(dateModel.hour);
48 | Log(dateModel.min);
49 | Log(dateModel.sec);
50 | Log("-------");
51 | int unixTime2 = DateConverter.JalaliToUnix(
52 | dateModel.year,
53 | dateModel.month,
54 | dateModel.day,
55 | dateModel.hour,
56 | dateModel.min,
57 | dateModel.sec);
58 | Log(unixTime2);
59 | Assert.assertTrue(unixTime == unixTime2);
60 | }
61 |
62 | @Test
63 | public void JalaliTest() {
64 | JalaliDateTime mDateTime = new JalaliDateTime((int) new Date().getTime(), TimeZoneHelper.getSystemTimeZone());
65 | Log(mDateTime.toLongString());
66 | }
67 |
68 | @Test
69 | public void HijriTest() {
70 | Log(DateConverter.IsHijriLeap(1439));
71 | }
72 |
73 | private void Log(Object s) {
74 | System.out.println(s);
75 | }
76 | }
--------------------------------------------------------------------------------