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

Added a Shared Version of LocalDateTome #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

skilesare
Copy link

I want to use this as a stable/shared type in another library and it seems that having the functions keeps it from being stored as stable/returned from functions properly. Some more work can be done to add conversion functions, but for now I'll leave it as is.

skilesare and others added 3 commits October 17, 2023 16:34
Added a Shared version of local timezone...should likely add some to/fromShared methods
@Gekctek
Copy link
Contributor

Gekctek commented Oct 17, 2023

@skilesare does this change i made work for you?
FixedTimeZone is weird cause its a variant thats annoying to deal with since they all evaluate to seconds
Added a toComponentsWithOffset() to the localdatetime

@skilesare
Copy link
Author

I was probably a bit quick with my requests here...basically, it looks like the types are set up well for classes that have a bunch of calculations branched off of them(which was exactly what was asked for). The issue is that you can't put classes in a stable variable and/or you can't send a class down as the response to a function because it is not a shared variable.

I guess what I'm saying is that we need some shared types and some functions like toShared and fromShared that can be used if you want to return a DateTime type as the result of a function(as opposed to dumping it to an Int).

I ended up crafting the types in my other project and they look like this:

public type Year = {
    year : Int;
  };

  public type Month = {
    month : Nat; //1 based
  };

  public type Day = {
    day : Nat; // 1 based
  };

  public type MonthDay = Month and Day;

  public type YearMonth = Month and Year;

  public type DateComponents = Year and Month and Day;

  public type TimeComponents = {
    hour : Nat;
    minute : Nat;
    second : Decimal;
  };

  public type FixedTimeZone = {
    #hours : Int;
    #seconds : Int;
  };

  public type Time = TimeComponents and {
    fixedTimeZone: FixedTimeZone;
  };


  public type DateTime = DateComponents and TimeComponents and {
    fixedTimeZone: FixedTimeZone
  };

I'm basically trying to create stable variables that I can use to store values that are defined in the XSD spec: https://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/datatypes.html#language

@Gekctek
Copy link
Contributor

Gekctek commented Oct 18, 2023

I guess Im still confused.
What would the signatures of the toShared and fromShared look like
My thought was that DateTime <-> Nanoseconds and LocalDateTime <-> ComponentsWithOffset
like LocalDateTime(componentsWithOffset, #fixed(#seconds(componentsWithOffset.offset));
I can make a helper function for that

@Gekctek
Copy link
Contributor

Gekctek commented Oct 18, 2023

hmmmm. well my solution only works if you dont modify the LocalDateTime since its fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants