Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Share Bear
Apr 27, 2004

Sapozhnik posted:

Proleptic Gregorian is actually pretty easy. The rules define three calendar cycles, which are:

If the year is divisible by 4, it's a leap year,
unless the year is divisible by 100, in which case it isn't a leap year,
unless the year is divisible by 400, in which case it is a leap year.

Note that the year 2000 is divisible by 400, so it conveniently sits at the top of all three of those cycles. Life would have been a lot easier if the UNIX epoch was defined to be Jan 1st 2000 instead of Jan 1st 1970, so let's adjust our epoch sec to y2k epoch secs (note that even real UNIX epoch secs aka time_t are always signed, so -ve epoch secs are in theory something you need to know how to handle anyway).

Taking divmod by 86400 gives us a number of days since y2k (quotient) and a number of seconds since midnight (remainder). This tuple forms a nice little structure I call a "linear datetime" that comes in handy by a whole bunch of other operations. Take care with your rounding rules here if the number is negative. Converting seconds since midnight into hh:mm:ss is trivial, so let's concentrate on converting y2k_days into yyyy-mm-dd.

Going through those cycles in reverse order, what do those really mean? It says that:

every 400-year cycle has 400 * 365 + (400/4) - (400/100) + (400/400) days in it,
every 100-year cycle has 100 * 365 + (100/4) - (100/100) days in it,
every 4-year cycle has 4 * 365 + (4/4) days in it, and
every 1-year cycle has 1 * 365 days in it.

So make that into a table of cycles, initialize your year at 2000, then just go down the table: divide by each period's day-length and add quotient * year-length to your current year, then feed the remainder into the next cycle's day-count input. Again, watch your carrying and your rounding if your y2k_day is negative.

So this leaves you with a year and a final remainder, your day-in-year. Apply the rules to your year number to determine if you've landed in a common year or leap year. From there the process of converting a day-in-year to a month-day pair is a pretty straightforward one, taking care to remember that the first day of each month is the 1st and not the 0th (and the first month is also the 1st month and not the 0th month).

aaand there you have it. UNIX epoch sec to yyyy-mm-ddThh:mm:ssZ.

i use gnu date 5.97 op

Adbot
ADBOT LOVES YOU

Share Bear
Apr 27, 2004

vodkat posted:

lol im a grad student, no one values my time, not even me :negative:

is it possible at all to work with the source to fix their bug

do they make it obvious they're using something specifically lovely and hand rolled

Share Bear
Apr 27, 2004

Hi,

This is the guy using your stuff. It looks like your JSON is not valid according to several known libraries and parsers. Maybe we can work together to fix up your broken poo poo?? What language are you using

Love,
the grad student with a heart of gold

Share Bear
Apr 27, 2004

Luigi Thirty posted:

I don't know what pattern I'm using for this 3D engine but I'm sure it's bad

i still dont understand what problem dependency injection or inversion of control or whatever the gently caress spring does is supposed to accomplish

this is not for a lack of trying

Share Bear
Apr 27, 2004

raminasi posted:

have you really never passed a callback to anything

not in java 6/7

Asymmetrikon posted:

or attempted to test something that interacts with the outside world heavily

we use a separate testing framework outside of whatever spring has made available; isnt that what interfaces or testing environments are for?

i both don't understand what problem it is solving (generic objects? not using interfaces?), nor the solution itself (PortletApplicationContext.HelpController1), mainly because I have never had to solve that problem

Share Bear fucked around with this message at 22:27 on Jun 20, 2017

Share Bear
Apr 27, 2004

Asymmetrikon posted:

all dependency injection is is "passing dependencies through the constructor/properties instead of constructing them inside the object." spring is a lot more than dependency injection, and you don't need a framework to do DI

e: also, DI often heavily relies on interfaces, so it definitely isn't about not using interfaces or generics

raminasi posted:

have you ever done a sort with a custom comparer

OK I understand the first part, the second part is "I'm not sure why you would do this versus declaring an interface", because I assume that anything that gets set as a dependency at runtime still has to adhere to an object type or interface

I get that it is like a lambda, but the object instance should still expect an interface which is defined, rather than just a function? Or that lambdas also have types and the type would be the object instance and that's it?

Share Bear
Apr 27, 2004

Shaggar posted:

w/ spring you can intercept a call to a method on an interface and handle it with whatever code you want. so instead of an object that fully implements an interface, you could have an object for each method in the interface and spring creates a proxy that acts like the interface, but behind the scenes redirects to the object responsible for each method.

this is very useful for things like mybatis-spring which allows you to create a proxy for an interface that sends the method calls to a mybatis translation layer which calls a sql statement using the inputs of the method and then returns the results of the statement as the return type defined in the interface method.

raminasi posted:

there's no "versus declaring an interface," capital letter DI as such relies heavily on interfaces. if a lambda is a single anonymous function, an interface is a named collection of one or more functions. and if you always want to pass the same set of functions in (outside of e.g. a testing environment) you do it at object construction. and if you don't want to do all the boilerplate yourself you do it with a framework.

Arcsech posted:

dependency injection is just a piece of code that calls all your constructors for you

you write all of your constructors to take interfaces, then your DI thinger figures out whether you want a real Butt for your IFartable or a FakeButt IFartable depending on whether you're in your test harness or not


Thank you all very much for your assistance with my very terrible programmer question, it has been extremely helpful for understanding this mess.

Share Bear
Apr 27, 2004

FAT32 SHAMER posted:

I was doing some googling and



so thanks thread!

i have googled this phrase many times and never got this

Adbot
ADBOT LOVES YOU

Share Bear
Apr 27, 2004

edit: wow a double post in 2017

  • Locked thread