bahmanm / persianutils   4.0

GitHub

A collection of utilities for Scala/Java developers who are targeting Persian (Farsi) speaking users.

Scala versions: 2.10 2.11 2.12 2.13

1 Introduction

A collection of utilities for Scala/Java developers who are targeting Persian (Farsi) speaking users.

1.1 Scala Compatibility

↓persianutils │ scala→ 2.10.x 2.11.x 2.12.x 2.13.x
2.x X X - -
3.x - X X -
4.x - X X X

2 Adding To Your Project

2.1 SBT

libraryDependencies ++= Seq(
    "com.bahmanm" %% "persianutils" % "4.0" // or 2.0
)

2.2 Maven

With Scala 2.13.x:

<dependencies>
    <dependency>
        <groupId>com.bahmanm</groupId>
        <artifactId>persianutils_2.13</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>

With Scala 2.12.x:

<dependencies>
    <dependency>
        <groupId>com.bahmanm</groupId>
        <artifactId>persianutils_2.12</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>

With Scala 2.11.x:

<dependencies>
    <dependency>
        <groupId>com.bahmanm</groupId>
        <artifactId>persianutils_2.11</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>

With Scala 2.10.x:

<dependencies>
    <dependency>
        <groupId>com.bahmanm</groupId>
        <artifactId>persianutils_2.10</artifactId>
        <version>2.0</version>
    </dependency>
</dependencies>

3 What Is Included?

This is a short review of what you will find in persianutils:

3.1 DateConverter

com.bahmanm.persianutils.DateConverter is the Scala port of the original algorithm (in Fortran) The Persian calendar for 3000 years.

3.1.1 Scala

NOTE: persianutils 3.x works with Scala 2.11.x and 2.12.x series. If you need to work with Scala 2.10.x, please use persianutils 2.0.

import com.bahmanm.persianutils.DateConverter._

// NOTE: months and days are 1-indexed, i.e. December is 12 or Farvardin is 1
val gDate1 = SimpleDate(2013, 12, 11)
val pDate1 = gregorianToPersian(gDate1)
print(pDate1)  // OUTPUT: SimpleDate(1392,9,20) -> 20om Azar 1392


val pDate2 = SimpleDate(1392, 1, 1)
val gDate2 = persianToGregorian(pDate2)
print(gDate2) // OUTPUT: SimpleDate(2013,3,21) -> March 21st 2013


val d = java.util.Calendar.getInstance().getTime()
val gDate3 = SimpleDate(date) // iniatlising from a java.util.Date
val pDate3 = gregorianToPersian(gDate3)


val ds = "1392/09/24"
val pDate4 = SimpleDate(ds) // initialising from a String
val gDate4 = persianToGregorian(pDate4)

3.1.2 Java

import com.bahmanm.persianutils.DateConverter;

public class Main {

  public static void main(String[] args) {
    DateConverter.SimpleDate pd1 = new DateConverter.SimpleDate(1392, 11, 11);
    DateConverter.SimpleDate gd1 = DateConverter.persianToGregorian(pd1);
    System.out.println(gd1);

    DateConverter.SimpleDate gd2 = new DateConverter.SimpleDate(2014, 2, 4);
    DateConverter.SimpleDate pd2 = DateConverter.gregorianToPersian(gd2);
    System.out.println(pd2);
  }

}

3.2 NumToWord

import com.bahmanm.persianutils.NumToWord

assert(NumToWord(100) == "صد")
assert(NumToWord(299792458) == "دویست و نود و نه میلیون و هفتصد و نود و دو هزار و چهارصد و پنجاه و هشت")

4 Contributors