core :: union_find
union–find algorithm using an efficient disjoint-set data structurenitc :: actors_generation_phase
Generate a support module for each module that contain a class annotated withis actor
nitc :: actors_injection_phase
Injects model for the classes annotated with "is actor" sonitc :: api_metrics
nitc :: astbuilder
Instantiation and transformation of semantic nodes in the AST of expressions and statementsbucketed_game :: bucketed_game
Game framework with an emphasis on efficient event coordinationcflags
and ldflags
to specify
accept_scroll_and_zoom
gamnit :: camera_control_android
Two fingers camera manipulation, pinch to zoom and slide to scrollgamnit :: camera_control_linux
Mouse wheel and middle mouse button to control cameranitc :: commands_ini
pthreads :: concurrent_array_and_barrier
A basic usage example of the modulespthreads
and pthreads::cocurrent_collections
pthreads :: concurrent_collections
Introduces thread-safe concurrent collectionsserialization :: custom_serialization
Example of an ad hoc serializer that is tailored to transform business specific objects into customized representation.nitc :: detect_variance_constraints
Collect metrics about detected variances constraints on formal types.egl
, sdl
and x11
extra_java_files
to compile extra java files
FileServer
action, which is a standard and minimal file server
cocoa :: foundation
The Foundation Kit provides basic Objective-C classes and structuresfunctional_types.nit
functional :: functional_types
This module provides functional type to represents various function forms.gtk :: gtk_assistant
gtk :: gtk_dialogs
HttpRequest
class and services to create it
app::http_request
main service AsyncHttpRequest
nitc :: i18n_phase
Basic support of internationalization through the generation of id-to-string tablesSerializable::inspect
to show more useful information
Iterator
.
nitc :: light_only
Compiler support for the light FFI only, detects unsupported usage of callbacksactors :: mandelbrot
Example implemented from "The computer Language Benchmarks Game" - Mandelbrotmarkdown2 :: markdown_html_rendering
HTML rendering of Markdown documentsmarkdown2 :: markdown_latex_rendering
LaTeX rendering of Markdown documentsmarkdown2 :: markdown_man_rendering
Manpages rendering of Markdown documentsmarkdown2 :: markdown_md_rendering
Markdown rendering of Markdown documentsnitc
.
nitc :: modelbuilder
more_collections :: more_collections
Highly specific, but useful, collections-related classes.mpi :: mpi_simple
curl :: native_curl
Binding of C libCurl which allow us to interact with network.app.nit
on Android using a custom Java entry point
nitcc_runtime :: nitcc_runtime
Runtime library required by parsers and lexers generated by nitccnitc :: nitmetrics
A program that collects various metrics on nit programs and librariesnitc :: nitrestful
Tool generating boilerplate code linking RESTful actions to Nit methodsnlp :: nlp_server
glesv2 :: opengles2_hello_triangle
Basic example of OpenGL ES 2.0 usage using SDL 2threaded
annotation
performance_analysis :: performance_analysis
Services to gather information on the performance of events by categoriesrestful
annotation documented at lib/nitcorn/restful.nit
sax :: sax_locator
Interface for associating a SAX event with a document location.Locator
.
nitc :: separate_erasure_compiler
Separate compilation of a Nit program with generic type erasurenitc :: serialization_code_gen_phase
Phase generating methods (code) to serialize Nit objectsmsgpack :: serialization_common
Serialization services forserialization_write
and serialization_read
serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsnitc :: serialization_model_phase
Phase generating methods (model-only) to serialize Nit objectsdeserialize_json
and JsonDeserializer
serialize_to_json
and JsonSerializer
msgpack :: serialization_write
Serialize full Nit objects to MessagePack formatroot
to execute
agent_simulation
by refining the Agent class to make
socket :: socket_simple_server
Simple server example using a non-blockingTCPServer
EulerCamera
and App::frame_core_draw
to get a stereoscopic view
clone
method of the astbuilder tool
gamnit :: texture_atlas_parser
Tool to parse XML texture atlas and generated Nit code to access subtexturesnitc :: toolcontext
Common command-line tool infrastructure than handle options and error messagesnitc :: uml_module
Services for generation of a UML package diagram based on aModel
# Management of time and dates
module time
import text
import stream
in "C Header" `{
#include <time.h>
#include <sys/time.h>
`}
# The number of seconds elapsed since January 1, 1970
#
# Uses the Unix function `time`.
fun get_time: Int `{ return time(NULL); `}
# The number of milliseconds elapsed since January 1, 1970
#
# Returns `get_microtime / 1000`
fun get_millitime: Int do return get_microtime / 1000
# The number of microseconds elapsed since January 1, 1970
#
# Uses the Unix function `gettimeofday`.
fun get_microtime: Int `{
struct timeval val;
gettimeofday(&val, NULL);
return val.tv_sec * 1000000 + val.tv_usec;
`}
redef class Sys
# Wait a specific number of second and nanoseconds
#
# Returns `true` if interrupted by a signal.
fun nanosleep(sec, nanosec: Int): Bool `{
const struct timespec req = {sec, nanosec};
return nanosleep(&req, NULL);
`}
end
redef class Int
# Sleep approximately `self` seconds
#
# Is not interrupted by signals.
fun sleep do to_f.sleep
end
redef class Float
# Sleep approximately `self` seconds
#
# Is not interrupted by signals.
fun sleep `{
time_t s = self;
long ns = (self-s) * 1000000000.0;
struct timespec req = {s, ns};
while (nanosleep(&req, &req)) { }
`}
end
# Time since epoch
extern class TimeT `{time_t`}
# Returns Time since epoch from now.
new `{ return time(NULL); `}
# Returns Time since epoch from `i` (expressed in seconds).
new from_i(i: Int) `{ return i; `}
# Update current time.
fun update `{ time(&self); `}
# Convert `self` to a human readable String.
fun ctime: String import CString.to_s `{
return CString_to_s( ctime(&self) );
`}
# Difference in secondes from start (self if the end time)
fun difftime(start: TimeT): Float `{ return difftime(self, start); `}
redef fun to_s do return ctime.replace("\n", "")
# Convert self to Int (expressed as seconds since epoch).
fun to_i: Int `{ return (int)self; `}
end
# Time structure
extern class Tm `{struct tm *`}
# Create a new Time structure expressed in Coordinated Universal Time (UTC).
new gmtime `{
struct tm *tm;
time_t t = time(NULL);
tm = gmtime(&t);
return tm;
`}
# Create a new Time structure expressed in UTC from `t`.
new gmtime_from_timet(t: TimeT) `{
struct tm *tm;
tm = gmtime(&t);
return tm;
`}
# Create a new Time structure expressed in the local timezone.
new localtime `{
struct tm *tm;
time_t t = time(NULL);
tm = localtime(&t);
return tm;
`}
# Create a new Time structure expressed in the local timezone from `t`.
new localtime_from_timet(t: TimeT) `{
struct tm *tm;
tm = localtime(&t);
return tm;
`}
# Convert `self` as a TimeT.
fun to_timet: TimeT `{ return mktime(self); `}
# Seconds after the minute.
fun sec: Int `{ return self->tm_sec; `}
# Minutes after the hour.
fun min: Int `{ return self->tm_min; `}
# hours since midnight.
fun hour: Int `{ return self->tm_hour; `}
# Day of the month.
fun mday: Int `{ return self->tm_mday; `}
# Months since January.
fun mon: Int `{ return self->tm_mon; `}
# Years since 1900.
fun year: Int `{ return self->tm_year; `}
# Days since Sunday.
fun wday: Int `{ return self->tm_wday; `}
# Days since January 1st.
fun yday: Int `{ return self->tm_yday; `}
# Is `self` in Daylight Saving Time.
fun is_dst: Bool `{ return self->tm_isdst; `}
# Convert `self` to a human readable String.
private fun asctime: CString `{ return asctime(self); `}
# Convert `self` to a human readable String corresponding to `format`.
# TODO document allowed format.
fun strftime(format: String): String import String.to_cstring, CString.to_s `{
char* buf, *c_format;
buf = (char*)malloc(100);
c_format = String_to_cstring(format);
strftime(buf, 100, c_format, self);
String s = CString_to_s(buf);
free(buf);
return s;
`}
redef fun to_s do return asctime.to_s.replace("\n", "")
end
# Date using the international format defined by ISO 8601.
#
# Usage:
#
# # By default ISODate at today.
# var date = new ISODate
# var tm = new Tm.localtime
# assert date.year == tm.year + 1900
# assert date.month == tm.mon + 1
# assert date.day == tm.mday
#
# # ISODate can be initialized from a String.
# date = new ISODate.from_string("1970-01-01T00:00:00Z")
# assert date.year == 1970
# assert date.month == 1
# assert date.day == 1
#
# # ISODate can be printed as String following the ISO format.
# assert date.to_s == "1970-01-01T00:00:00Z"
#
# Note that only the `YYYY-MM-DDTHH:MM:SSZ` is supported for now.
#
# See <http://www.w3.org/QA/Tips/iso-date>
class ISODate
super Comparable
# UTC years as Int.
var year: Int is noinit
# UTC months as Int (`1` for January).
var month: Int is noinit
# UTC days as Int (starting at `1`).
var day: Int is noinit
# UTC hours as Int.
var hours: Int is noinit
# UTC minutes as Int.
var minutes: Int is noinit
# UTC seconds as Int.
var seconds: Int is noinit
# UTC timezone marker.
#
# Note that I don't know what will happen if you change this value...
var timezone = "Z"
init do
var t = new Tm.localtime
year = 1900 + t.year
month = t.mon + 1
day = t.mday
hours = t.hour
minutes = t.min
seconds = t.sec
end
# Init `self` from a ISODate formatted string.
init from_string(str: String) do
year = str.substring(0, 4).to_i
month = str.substring(5, 2).to_i
day = str.substring(8, 2).to_i
hours = str.substring(11, 2).to_i
minutes = str.substring(14, 2).to_i
seconds = str.substring(17, 2).to_i
timezone = str.substring(19, str.length)
end
redef fun to_s do
var buff = new FlatBuffer
buff.append year.to_s
buff.add '-'
if month < 10 then buff.add '0'
buff.append month.to_s
buff.add '-'
if day < 10 then buff.add '0'
buff.append day.to_s
buff.add 'T'
if hours < 10 then buff.add '0'
buff.append hours.to_s
buff.add ':'
if minutes < 10 then buff.add '0'
buff.append minutes.to_s
buff.add ':'
if seconds < 10 then buff.add '0'
buff.append seconds.to_s
buff.append timezone
return buff.write_to_string
end
redef type OTHER: ISODate
# TODO handle timezones
redef fun <(o) do return to_s < o.to_s
end
lib/core/time.nit:14,1--279,3