diff options
author | Robbie Cronin <robert.cronin@uqconnect.edu.au> | 2019-05-08 17:47:09 +0800 |
---|---|---|
committer | Robbie Cronin <robert.cronin@uqconnect.edu.au> | 2019-05-08 17:47:09 +0800 |
commit | e1846905b0d0a3e54e798683fd468832eff71084 (patch) | |
tree | 3a0a061667e1acd62512f9b9e96c3388fbec08e3 /kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft | |
parent | 63767fec9660bdcbfd041ec28fb76ba95b322f2a (diff) | |
download | kvision-e1846905b0d0a3e54e798683fd468832eff71084.tar.gz kvision-e1846905b0d0a3e54e798683fd468832eff71084.tar.bz2 kvision-e1846905b0d0a3e54e798683fd468832eff71084.zip |
Add momentjs wrapper to kvision-modules
Diffstat (limited to 'kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft')
3 files changed, 222 insertions, 0 deletions
diff --git a/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/KVManagerMoment.kt b/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/KVManagerMoment.kt new file mode 100644 index 00000000..b1a35552 --- /dev/null +++ b/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/KVManagerMoment.kt @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision + +import pl.treksoft.kvision.require + +internal val kVManagerMomentInit = KVManagerMoment.init() + +/** + * Internal singleton object which initializes and configures KVision Moment module. + */ +@Suppress("EmptyCatchBlock", "TooGenericExceptionCaught") +internal object KVManagerMoment { + fun init() {} + + private val moment = try { + require("moment/min/moment-with-locales.js") + } catch (e: Throwable) {} +} diff --git a/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/Options.kt b/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/Options.kt new file mode 100644 index 00000000..fef685e0 --- /dev/null +++ b/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/Options.kt @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.fleethome.util.kvision + +import pl.treksoft.kvision.utils.obj +import kotlin.js.Promise + +/** + * Format Display Option. + */ +enum class FormatDisplayOption(internal val displayOption: String) { + MonthM("M"), + MonthMo("Mo"), + MonthMM("MM"), + MonthMMM("MMM"), + MonthMMMM("MMMM"), + QuarterQ("Q"), + QuarterQo("Qo"), + DayOfMonthD("D"), + DayOfMonthDo("Do"), + DayOfMonthDD("DD"), + DayOfYearDDD("DDD"), + DayOfYearDDDo("DDDo"), + DayOfYearDDDD("DDDD"), + DayOfWeekdo("do"), + DayOfWeekdd("dd"), + DayOfWeekddd("ddd"), + DayOfWeekdddd("dddd"), + DayOfWeekLocale("e"), + DayOfWeekISO("E"), + WeekOfYearw("w"), + WeekOfYearwo("wo"), + WeekOfYearww("ww"), + WeekOfYearISOW("W"), + WeekOfYearISOWo("Wo"), + WeekOfYearISOWW("WW"), + YearYY("YY"), + YearYYYY("YYYY"), + YearY("Y"), + WeekYeargg("gg"), + WeekYeargggg("gggg"), + WeekYearISOGG("GG"), + WeekYearISOGGGG("GGGG"), + AmPmUpperCase("A"), + AmPmLowerCase("a"), + HourH("H"), + HourHH("HH"), + Hourh("h"), + Hourhh("hh"), + Hourk("k"), + Hourkk("kk"), + Minutem("m"), + Minutemm("mm"), + Seconds("s"), + Secondss("ss"), + FractionalSecondS("S"), + FractionalSecondSS("SS"), + FractionalSecondSSS("SSS"), + FractionalSecondSSSS("SSSS"), + TimeZoneZ("Z"), + TimeZoneZZ("ZZ"), + Unix("X"), + UnixMM("x") +} + +/** + * Localized Format Display Option. + */ +enum class LocalizedFormatDisplayOption(internal val displayOption: String) { + LT("LT"), + LTS("LTS"), + L("L"), + l("l"), + LL("LL"), + ll("ll"), + LLL("LLL"), + lll("lll"), + LLLL("LLLL"), + llll("llll") +}
\ No newline at end of file diff --git a/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/js/Moment.kt b/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/js/Moment.kt new file mode 100644 index 00000000..95827ce6 --- /dev/null +++ b/kvision-modules/kvision-moment/src/main/kotlin/pl/treksoft/kvision/js/Moment.kt @@ -0,0 +1,84 @@ +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION", + "NESTED_CLASS_IN_EXTERNAL_INTERFACE", + "unused", "PropertyName", "TooManyFunctions", "VariableNaming", "MaxLineLength" +) + +package pl.treksoft.kvision.moment.js + +import com.fleethome.util.kvision.FormatDisplayOption +import com.fleethome.util.kvision.LocalizedFormatDisplayOption +import kotlin.js.Date + +@Suppress("ClassName") +@JsNonModule +@JsModule("moment") +open external class Moment { + constructor(dateArray: Array<dynamic>) + constructor(dateString: String, patter: String) + constructor(dateString: String) + constructor(date: Date) + constructor() + + open fun add(duration: dynamic, key: String): dynamic = definedExternally + open fun subtract(duration: dynamic, key: String): dynamic = definedExternally + open fun startOf(key: String): dynamic = definedExternally + open fun endOf(key: String): dynamic = definedExternally + open fun local(): dynamic = definedExternally + open fun utc(): dynamic = definedExternally + open fun utcOffset(): dynamic = definedExternally + open fun utcOffset(amount: dynamic): dynamic = definedExternally + open fun utcOffset(amount: dynamic, keepExistingTimeOfDay: Boolean): dynamic = definedExternally + open fun format(pattern: String): dynamic = definedExternally + open fun format(displayOption: FormatDisplayOption): dynamic = definedExternally + open fun format(localizedDisplayOption: LocalizedFormatDisplayOption): dynamic = definedExternally + open fun format(): dynamic = definedExternally + open fun fromNow(): dynamic = definedExternally + open fun fromNow(withoutSuffix: Boolean): dynamic = definedExternally + open fun from(moment: dynamic): dynamic = definedExternally + open fun from(withoutSuffix: Boolean): dynamic = definedExternally + open fun toNow(): dynamic = definedExternally + open fun toNow(withoutPrefix: Boolean): dynamic = definedExternally + open fun to(moment: dynamic): dynamic = definedExternally + open fun to(withoutPrefix: Boolean): dynamic = definedExternally + open fun calendar(): dynamic = definedExternally + open fun calendar(referenceTime: dynamic): dynamic = definedExternally + open fun calendar(referenceTime: dynamic, formats: dynamic): dynamic = definedExternally + open fun diff(moment: dynamic): dynamic = definedExternally + open fun diff(moment: dynamic, key: dynamic): dynamic = definedExternally + open fun diff(moment: dynamic, key: dynamic, floatingPoint: Boolean): dynamic = definedExternally + open fun valueOf(): dynamic = definedExternally + open fun unix(): dynamic = definedExternally + open fun daysInMonth(): dynamic = definedExternally + open fun toDate(): dynamic = definedExternally + open fun toArray(): dynamic = definedExternally + open fun toJSON(): dynamic = definedExternally + open fun toISOString(): dynamic = definedExternally + open fun toISOString(keepOffset: Boolean): dynamic = definedExternally + open fun toObject(): dynamic = definedExternally + open fun inspect(): dynamic = definedExternally + open fun isBefore(moment: dynamic): Boolean = definedExternally + open fun isBefore(moment: dynamic, key: String): Boolean = definedExternally + open fun isSame(moment: dynamic): Boolean = definedExternally + open fun isSame(moment: dynamic, key: String): Boolean = definedExternally + open fun isAfter(moment: dynamic): Boolean = definedExternally + open fun isAfter(moment: dynamic, key: String): Boolean = definedExternally + open fun isSameOrBefore(moment: dynamic): Boolean = definedExternally + open fun isSameOrBefore(moment: dynamic, key: String): Boolean = definedExternally + open fun isSameOrAfter(moment: dynamic): Boolean = definedExternally + open fun isSameOrAfter(moment: dynamic, key: String): Boolean = definedExternally + open fun isBetween(firstMoment: dynamic, secondMoment: dynamic): Boolean = definedExternally + open fun isBetween(firstMoment: dynamic, secondMoment: dynamic, key: String, inclusivity: String): Boolean = definedExternally + open fun isBetween(firstMoment: dynamic, secondMoment: dynamic, key: String): Boolean = definedExternally + open fun isDST(): Boolean = definedExternally + open fun isDSTShifted(): Boolean = definedExternally + open fun isLeapYear(): Boolean = definedExternally + open fun locale(locale: String): dynamic = definedExternally + open fun locale(resetLocale: Boolean): dynamic = definedExternally + open fun lang(locale: String): dynamic = definedExternally + open fun lang(resetLocale: Boolean): dynamic = definedExternally +} |