Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OffsetDateTime type (tso) #319

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ object Primitive {
override def aliases: List[TypeName] = List("tsz", "datetimez", "dtz")
}

/**
* Date, Time and Offset
*/
case object TTsO extends Primitive with TimeTypeId {
override def aliases: List[TypeName] = List("tso", "datetimeo", "dto")
}

/**
* Date, Time and Timezone, but Timezone is always set to UTC
*/
Expand Down Expand Up @@ -246,6 +253,7 @@ object Primitive {
, TDate
, TTsTz
, TTsU
, TTsO
, TTs
, TBLOB
,
Expand Down Expand Up @@ -316,5 +324,3 @@ object Generic {
.flatMap(tpe => tpe.aliases.map(a => a -> tpe))
.toMap
}


Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public O Unmarshal<O>(string data) {
if (to == typeof(WebSocketRequestMessageJson) || to == typeof(WebSocketResponseMessageJson)) {
return JsonConvert.DeserializeObject<O>(data, webSocketConverters);
}

return JsonConvert.DeserializeObject<O>(data, settings);
}

Expand All @@ -81,7 +81,7 @@ public override InterfaceMarshalWorkaround ReadJson(JsonReader reader, System.Ty
throw new Exception("Should not be used for Reading, workaround only for writing.");
}
}

private class WebSocketMessageBase_JsonNetConverter: JsonNetConverter<WebSocketMessageBase> {
public override void WriteJson(JsonWriter writer, WebSocketMessageBase holder, JsonSerializer serializer) {
throw new Exception("WebSocketMessageBase should never be serialized.");
Expand All @@ -90,34 +90,34 @@ public override void WriteJson(JsonWriter writer, WebSocketMessageBase holder, J
public override WebSocketMessageBase ReadJson(JsonReader reader, System.Type objectType, WebSocketMessageBase existingValue, bool hasExistingValue, JsonSerializer serializer) {
var json = JObject.Load(reader);
var kind = json["kind"].Value<string>();

var res = hasExistingValue ? existingValue : new WebSocketMessageBase(kind);
res.Kind = kind;
return res;
}
}

private class WebSocketFailureMessage_JsonNetConverter: JsonNetConverter<WebSocketFailureMessage> {
public override void WriteJson(JsonWriter writer, WebSocketFailureMessage holder, JsonSerializer serializer) {
writer.WriteStartObject();
// Kind
writer.WritePropertyName("kind");
writer.WriteValue(holder.Kind);

// Cause
writer.WritePropertyName("cause");
writer.WriteValue(holder.Cause);

// Data
writer.WritePropertyName("data");
writer.WriteValue(holder.Data);

writer.WriteEndObject();
}

public override WebSocketFailureMessage ReadJson(JsonReader reader, System.Type objectType, WebSocketFailureMessage existingValue, bool hasExistingValue, JsonSerializer serializer) {
var json = JObject.Load(reader);

var kind = json["kind"].Value<string>();
var res = hasExistingValue ? existingValue : new WebSocketFailureMessage();
res.Kind = kind;
Expand All @@ -133,29 +133,29 @@ public override void WriteJson(JsonWriter writer, WebSocketRequestMessageJson ho
// Kind
writer.WritePropertyName("kind");
writer.WriteValue(holder.Kind);

// ID
writer.WritePropertyName("id");
writer.WriteValue(holder.ID);

// Service
if (!string.IsNullOrEmpty(holder.Service)) {
writer.WritePropertyName("service");
writer.WriteValue(holder.Service);
}

// Method
if (!string.IsNullOrEmpty(holder.Method)) {
writer.WritePropertyName("method");
writer.WriteValue(holder.Method);
}

// Headers
if (holder.Headers != null && holder.Headers.Count > 0) {
writer.WritePropertyName("headers");
writer.WriteValue(holder.Headers);
}

// Data
if (!string.IsNullOrEmpty(holder.Data)) {
writer.WritePropertyName("data");
Expand All @@ -167,7 +167,7 @@ public override void WriteJson(JsonWriter writer, WebSocketRequestMessageJson ho

public override WebSocketRequestMessageJson ReadJson(JsonReader reader, System.Type objectType, WebSocketRequestMessageJson existingValue, bool hasExistingValue, JsonSerializer serializer) {
var json = JObject.Load(reader);

var kind = json["kind"].Value<string>();

var res = hasExistingValue ? existingValue : new WebSocketRequestMessageJson(kind);
Expand All @@ -184,18 +184,18 @@ public override WebSocketRequestMessageJson ReadJson(JsonReader reader, System.T
return res;
}
}

private class WebSocketResponseMessage_JsonNetConverter: JsonNetConverter<WebSocketResponseMessageJson> {
public override void WriteJson(JsonWriter writer, WebSocketResponseMessageJson holder, JsonSerializer serializer) {
writer.WriteStartObject();
// Kind
writer.WritePropertyName("kind");
writer.WriteValue(holder.Kind);

// Ref
writer.WritePropertyName("ref");
writer.WriteValue(holder.Ref);

// Data
if (!string.IsNullOrEmpty(holder.Data)) {
writer.WritePropertyName("data");
Expand All @@ -207,7 +207,7 @@ public override void WriteJson(JsonWriter writer, WebSocketResponseMessageJson h
public override WebSocketResponseMessageJson ReadJson(JsonReader reader, System.Type objectType, WebSocketResponseMessageJson existingValue, bool hasExistingValue, JsonSerializer serializer) {
var json = JObject.Load(reader);
var kind = json["kind"].Value<string>();

var res = hasExistingValue ? existingValue : new WebSocketResponseMessageJson(kind);
res.Kind = kind;
res.Ref = json["ref"].Value<string>();
Expand All @@ -221,7 +221,7 @@ public override WebSocketResponseMessageJson ReadJson(JsonReader reader, System.
if (reader.Value != null) {
if (reader.TokenType == JsonToken.PropertyName) {
Console.WriteLine("Found: " + reader.Value);

switch (reader.Value) {
case "ref": res.Ref = reader.ReadAsString();
break;
Expand Down Expand Up @@ -306,6 +306,8 @@ public static class JsonNetTimeFormats {

public static readonly string TsuDefault = "yyyy-MM-ddTHH:mm:ss.fffZ";
public static readonly string[] Tsu = JsonNetTimeFormats.Tsz;
public static readonly string TsoDefault = JsonNetTimeFormats.TszDefault;
public static readonly string[] Tso = JsonNetTimeFormats.Tsz;
}

class JsonNetDateConverter : IsoDateTimeConverter {
Expand All @@ -331,4 +333,4 @@ public JsonNetDateTimeZonedConverter() {
base.DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fffzzz";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ func ReadUTCDateTime(value string) (time.Time, error) {
func WriteUTCDateTime(value time.Time) string {
return value.UTC().Format("2006-01-02T15:04:05.000Z")
}

func ReadOffsetDateTime(value string) (time.Time, error) {
return ReadDateTime(value, false)
}

func WriteOffsetDateTime(value time.Time) string {
return value.Format("2006-01-02T15:04:05.000-07:00")
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,12 @@ export class Formatter {
public static writeUTCDateTime(value: Date): string {
return moment(value).utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
}

public static readOffsetDateTime(value: string): Date {
return Formatter.readDateTime(value, false);
}

public static writeOffsetDateTime(value: Date): string {
return moment(value).format('YYYY-MM-DDTHH:mm:ss.SSSZ');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum IntrospectorTypes {
Tsz,
Tsl,
Tsu,
Tso,
Time,
Date
}
Expand Down Expand Up @@ -143,4 +144,4 @@ export class Introspector {
public static all(): IIntrospectorObject[] {
return Introspector.knownTypesList;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mixin AllTypes {
ts : tsz
tslocal : tsl
tsuni : tsu
tsofs : tso
time : time
date : date

Expand Down Expand Up @@ -210,6 +211,10 @@ data TsuData {
since: tsu
}

data TsoData {
since: tso
}

mixin CommonFailure {
code: i32
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ object IDLTestTools {
val manifest = mf.copy(layout = ScalaProjectLayout.SBT, sbt = mf.sbt.copy(projectNaming = mf.sbt.projectNaming.copy(dropFQNSegments = Some(1))))
val out = compiles(id, domains, CompilerOptions(IDLLanguage.Scala, extensions, manifest))
val classpath: String = IzJvm.safeClasspath()
val safeClasspath = s"\"$classpath\""

val cmd = layout match {
case ScalaProjectLayout.PLAIN =>
// it's hard to map volumes on CI agent bcs our build runs in docker but all the mounts happens on the docker host
if (useDockerForLocalTest && hasDocker && !isCI) {
dockerRun(out, classpath, scala213 = true)
dockerRun(out, safeClasspath, scala213 = true)
} else {
directRun(out, classpath)
directRun(out, safeClasspath)
}

case ScalaProjectLayout.SBT =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package izumi.idealingua.translator.tocsharp

import izumi.fundamentals.platform.language.Quirks
import izumi.idealingua.model.common.TypeId._
import izumi.idealingua.model.common.{Generic, Package, Primitive, TypeId}
import izumi.idealingua.model.problems.IDLException
import izumi.idealingua.model.common.TypeId.*
import izumi.idealingua.model.common.{Generic, Package, Primitive, PrimitiveId, ScalarId, StructureId, TypeId}
import izumi.idealingua.model.il.ast.typed.DefMethod.Output.{Algebraic, Alternative, Singular, Struct, Void}
import izumi.idealingua.model.il.ast.typed.DefMethod.RPCMethod
import izumi.idealingua.model.il.ast.typed.TypeDef._
import izumi.idealingua.model.il.ast.typed.TypeDef.*
import izumi.idealingua.model.il.ast.typed.{Buzzer, DefMethod, Service, TypeDef}
import izumi.idealingua.model.problems.IDLException
import izumi.idealingua.model.typespace.Typespace
import izumi.idealingua.translator.tocsharp.types.CSharpType

Expand Down Expand Up @@ -75,17 +75,23 @@ object CSharpImports {
case Primitive.TTs => return Seq("System", "IRT", "System.Globalization")
case Primitive.TTsTz => return Seq("System", "IRT", "System.Globalization")
case Primitive.TTsU => return Seq("System", "IRT", "System.Globalization")
case Primitive.TTsO => return Seq("System", "IRT", "System.Globalization")
case Primitive.TDate => return Seq("System")
case Primitive.TUUID => return Seq("System")
case Primitive.TFloat =>
case Primitive.TDouble =>
case Primitive.TBLOB => ???
case g: Generic => g match {
case _: Generic.TOption => return Seq("System")
case _: Generic.TMap => return Seq("System.Collections", "System.Collections.Generic")
case _: Generic.TList => return Seq("System.Collections", "System.Collections.Generic")
case _: Generic.TSet => return Seq("System.Collections", "System.Collections.Generic")
}
case _: Primitive => return Seq.empty
case _ =>
case _: PrimitiveId =>
case _: StructureId =>
case _: ScalarId =>
case _: AdtId =>
case _: AliasId =>
}

if (t.path.toPackage.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package izumi.idealingua.translator.tocsharp.extensions

import izumi.fundamentals.platform.language.Quirks.discard
import izumi.fundamentals.platform.strings.IzString._
import izumi.idealingua.model.common.TypeId._
import izumi.idealingua.model.common.{Generic, Primitive, TypeId}
import izumi.fundamentals.platform.strings.IzString.*
import izumi.idealingua.model.common.TypeId.*
import izumi.idealingua.model.common.{Generic, Primitive, TimeTypeId, TypeId}
import izumi.idealingua.model.problems.IDLException
import izumi.idealingua.model.il.ast.typed.DefMethod
import izumi.idealingua.model.il.ast.typed.DefMethod.Output.{Alternative, Singular}
import izumi.idealingua.model.il.ast.typed.TypeDef._
import izumi.idealingua.model.il.ast.typed.TypeDef.*
import izumi.idealingua.model.typespace.Typespace
import izumi.idealingua.translator.tocsharp.types.{CSharpClass, CSharpField, CSharpType}
import izumi.idealingua.translator.tocsharp.{CSTContext, CSharpImports}
Expand Down Expand Up @@ -171,6 +171,7 @@ object JsonNetExtension extends CSharpTranslatorExtension {
case Primitive.TDate => s"""writer.WriteValue($src.ToString("yyyy-MM-dd"));"""
case Primitive.TTs => s"""writer.WriteValue($src.ToString(JsonNetTimeFormats.TslDefault, CultureInfo.InvariantCulture));"""
case Primitive.TTsTz => s"""writer.WriteValue($src.ToString($src.Kind == DateTimeKind.Utc ? JsonNetTimeFormats.TsuDefault : JsonNetTimeFormats.TszDefault, CultureInfo.InvariantCulture));"""
case Primitive.TTsO => s"""writer.WriteValue($src.ToString($src.Kind == DateTimeKind.Utc ? JsonNetTimeFormats.TsuDefault : JsonNetTimeFormats.TsoDefault, CultureInfo.InvariantCulture));"""
case Primitive.TTsU => s"""writer.WriteValue($src.ToUniversalTime().ToString(JsonNetTimeFormats.TsuDefault, CultureInfo.InvariantCulture));"""
}

Expand Down Expand Up @@ -210,11 +211,7 @@ object JsonNetExtension extends CSharpTranslatorExtension {
case Primitive.TFloat => false
case Primitive.TDouble => false
case Primitive.TUUID => false
case Primitive.TTime => false
case Primitive.TDate => false
case Primitive.TTs => false
case Primitive.TTsTz => false
case Primitive.TTsU => false
case _: TimeTypeId => false
case Primitive.TBLOB => ???
}
case c => c match {
Expand Down Expand Up @@ -323,6 +320,7 @@ object JsonNetExtension extends CSharpTranslatorExtension {
case Primitive.TDate => s"DateTime.Parse($src.Value<string>())"
case Primitive.TTs => s"DateTime.ParseExact($src.Value<string>(), JsonNetTimeFormats.Tsl, CultureInfo.InvariantCulture, DateTimeStyles.None)"
case Primitive.TTsTz => s"DateTime.ParseExact($src.Value<string>(), JsonNetTimeFormats.Tsz, CultureInfo.InvariantCulture, DateTimeStyles.None)"
case Primitive.TTsO => s"DateTime.ParseExact($src.Value<string>(), JsonNetTimeFormats.Tso, CultureInfo.InvariantCulture, DateTimeStyles.None)"
case Primitive.TTsU => s"DateTime.ParseExact($src.Value<string>(), JsonNetTimeFormats.Tsu, CultureInfo.InvariantCulture, DateTimeStyles.None)"
}
case _ => t.id match {
Expand Down
Loading