std.gregorian contribution

negerns negerns at gmail.com
Sun May 16 15:21:30 PDT 2010


I filled in some of the functions from Andrei's first draft of 
std.gregorian module. I hope they are good enough.

I changed some identifiers like GregYear, GregMonth, etc to 
GregorianYear, GregorianMonth, etc so as to be consistent with the 
'julian' identifiers but it's a minor changes that maybe I shouldn't 
have touched.

Also, I have introduced a unjoin() function as a helper function. It 
splits a string into an array of lines using the specified array of 
characters as delimiters. I am not sure if there is already an existing 
function that does the same but I could not find it. For lack of a 
better word I opted for the opposite of the join() function in std.string.

string[] unjoin(string s, char[] ch)
{
     uint start = 0;
     uint i = 0;
     string[] result;

     for (i = 0; i < s.length; i++) {
         if (indexOf(ch, s[i]) != -1) {
             result ~= s[start..i];
             start = i + 1;
         }
     }
     if (start < i) {
         result ~= s[start..$];
     }
     return result;
}

unittest {
     string s = "2010-05-31";
     string[] r = unjoin(s, ['/', '-', '.', ',', '\\']);
     assert(r[0] == "2010");
     assert(r[1] == "05");
     assert(r[2] == "31");
}

I have modified the signature of fromString() and 
fromUndelimitedString() to accept string arguments instead of char[]. I 
am not sure if it is alright with Andrei.

Here's a list of what I have implemented so far:
- Date fromString(in string s)
- Date fromUndelimitedString(in string s)
- @property string toSimpleString()
- @property string toIsoString()
- @property string toIsoExtendedString()
- added string[] months used only by toSimpleString()
- unit tests

I have attached the .diff file gregorian.diff

Regards,
negerns
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gregorian.diff
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100517/6360b6ad/attachment-0001.ksh>


More information about the Digitalmars-d mailing list