lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Jun 14, 2011 at 7:36 AM, Dave Collins
<Dave.Collins@mercatustechnologies.com> wrote:
>
> My API delivers dates in the form yyyy-mm-dd but my design team wants DDD dd (i.e. Tue 14).
>
> Can anyone point me at a reliable algorithm for calculating day-of-week from a standard datestamp?

You might take a look through my Lua date/time resource notes,
attached. You might find what you're looking for in one of the linked
web pages.

Best regards,

Paul
Title: Lua Date-Time Resources

Lua Date-Time Resources


Table of contents


Date/Time-Related Specifications

Specs that share ISO 8601 formatting in common.

CalDAV RFC 4791

The CalDAV specification was first published in 2003 as an Internet Draft submitted to the Internet Engineering Task Force (IETF). In March 2007, the CalDAV specification was described in the RFC 4791CalDAV is designed for implementation by any collaborative software, client or server, that needs to maintain, access or share collections of events. It is developed as an open standard to foster interoperability between software from different implementers.

The architecture of CalDAV (partially inherited from the underlying specifications) organizes the data (events, tasks, free-busy info, notes) in directories (collections), where multiple items (resources) reside. The resources and collections can be accessed by one or more users, using standard HTTP and DAV semantics to detect conflicting changes, or to provide locking.

For access control the concept of ACLs are used, so each operation (view, edit, delete etc.) can be denied or granted per user. Therefore the specification requires that CalDAV servers must support "WebDAV Access Control Protocol" (RFC 3744). The calendar resources must use iCalendar format, which allows the server to understand and process the data. Parsing the iCalendar items is necessary, because the server has to support a number of calendaring-specific operations such as doing free-busy time reports and expansion of recurring events. With this functionality, a user may synchronize his or her own calendar to a CalDAV server, and share it among multiple devices or with other users. The protocol also supports non-personal calendars, such as calendars for sites or organizations.
Pasted from <http://en.wikipedia.org/wiki/CalDAV>

Content Management Interoperability Services

Content Management Interoperability Services, http://en.wikipedia.org/wiki/Content_Management_Interoperability_Services

A recent standard from OASIS that has an incredible amount of adoption already, designed originally for interoperability between Enterprise Content Management (ECM) systems. CMIS treats data as objects and brokers the exchange of the objects between systems. I.e., one ECM system could be using iCalendar and another a different specification for tasks, calendar entries, and journal entries, but the two systems could still interoperate if using CMIS as the brokering layer.

Handles far more than the iCalendar data set.

GroupDAV

GroupDAV is a computer protocol used to connect Open Source groupware clients with Open Source groupware servers. It is a lightweight protocol whose primary design goal is to be as simple as possible to implement, focusing more on real world issues with open source applications than on an extremely extensive command set. It is based on a subset of WebDAV.
http://en.wikipedia.org/wiki/GroupDAV

hCalendar

hCalendar seems the best method I've hit so far for marking up iCalendar entries in HTML, including date/times. The result will display in web pages.

 hCalendar is a simple, open, distributed calendaring and events format, using a 1:1 representation of standard iCalendar (RFC2445) VEVENT properties and values in semantic HTML or XHTML. hCalendar is one of several open microformat standards suitable for embedding in HTML, XHTML, Atom, RSS, and arbitrary XML.

Want to get started with writing an hCalendar event? Use the hCalendar creator to write up an event and publish it, or follow the hCalendar authoring tips to add hCalendar markup to your page of upcoming events or events you mention in blog posts, wikis, etc.

Introduction

The iCalendar standard (RFC2445), has been broadly interoperably implemented (e.g. Apple's "iCal" application built into MacOSX).

In addition, bloggers often discuss events on their blogs -- upcoming events, writeups of past events, etc. With just a tad bit of structure, bloggers can discuss events in their blog(s) in such a way that spiders and other aggregators can retrieve such events, automatically convert them to iCalendar, and use them in any iCalendar application or service.

This specification introduces the hCalendar format, which is a 1:1 representation of the aforementioned iCalendar standard, in semantic HTML. Bloggers can both embed hCalendar events directly in their web pages, and style them with CSS to make them appear as desired. In addition, hCalendar enables applications to retrieve information about such events directly from web pages without having to reference a separate file.
Pasted from <http://microformats.org/wiki/hcalendar>

Wikipedia page, http://en.wikipedia.org/wiki/HCalendar (overview, links to related resources).

iCalendar RFC 2445

http://tools.ietf.org/html/rfc2445; see also Wikipedia page, http://en.wikipedia.org/wiki/Icalendar (overview, links to related resources).

Note that iCalendar RFC 5545 WebCal obsoleted RFC 2445 iCalendar in September of 2009.

This MIME media type provides a standard content type for capturing calendar event, to-do and journal entry information. It also can be used to convey free/busy time information. The content type is suitable as a MIME message entity that can be transferred over MIME based email systems, using HTTP or some other Internet transport. In addition, the content type is useful as an object for interactions between desktop applications using the operating system clipboard, drag/drop or file systems capabilities.

This memo is based on the earlier work of the vCalendar specification for the exchange of personal calendaring and scheduling information. In order to avoid confusion with this referenced work, this memo is to be known as the iCalendar specification.

iCalendar RFC 5545

http://tools.ietf.org/html/rfc5545

Supercedes iCalendar RFC 2445, adds interoperability extensions.

This memo is intended to progress the level of interoperability possible between dissimilar calendaring and scheduling applications. This memo defines a MIME content type for exchanging electronic calendaring and scheduling information. The Internet Calendaring and Scheduling Core Object Specification, or iCalendar, allows for the capture and exchange of information normally stored within a calendaring and scheduling application; such as a Personal Information Manager (PIM) or a Group-Scheduling product.

The iCalendar format is suitable as an exchange format between applications or systems. The format is defined in terms of a MIME content type. This will enable the object to be exchanged using several transports, including but not limited to SMTP, HTTP, a file system, desktop interactive protocols such as the use of a memory- based clipboard or drag/drop interactions, point-to-point asynchronous communication, wired-network transport, or some form of unwired transport such as infrared.

The memo also provides for the definition of iCalendar object methods that will map this content type to a set of messages for supporting calendaring and scheduling operations such as requesting, replying to, modifying, and canceling meetings or appointments, to-dos, and journal entries. The iCalendar object methods can be used to define other calendaring and scheduling operations such as requesting for and replying with free/busy time data. Such a scheduling protocol is defined in the iCalendar Transport-independent Interoperability Protocol (iTIP) defined in [2446bis].

The memo also includes a formal grammar for the content type based on the Internet ABNF defined in [RFC5234]. This ABNF is required for the implementation of parsers and to serve as the definitive reference when ambiguities or questions arise in interpreting the descriptive prose definition of the memo. Additional restrictions that could not easily be expressed with the ABNF syntax are specified as comments in the ABNF. Comments with normative statements should be treated as such.

ISO 8601

ISO 8601 itself apparently is not available as a free specification. http://www.iso.org/iso/catalogue_detail?csnumber=40874 (130 Swiss Francs).

This description of it looks like it might be the functional equivalent. http://www.mcs.vuw.ac.nz/technical/software/SGML/doc/iso8601/ISO8601.html.

The Mathematics of the ISO 8601 Calendar, http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm. Useful information on the math underlying ISO 8601.

ISO 8601 Date and Time - Converting and implementing. Metalink collection plus snippets for conversion and implementation of ISO 8601. Includes algorithms for a variety of non-Lua programming languages (including C/‍​​C‍+) that might provide insights for Lua scripting. http://www.probabilityof.com/ISO8601.shtml.

ISO 8601 representation using the yyyy-MM-dd'T'HH:mm:ss.SSSZZ format, e.g. "2010-10-14T19:01:24.944+00:00".

Lua Libraries

Date and Time Lua Library

Date and Time library for Lua 5.x, public domain, http://luaforge.net/projects/date/ (Another page says about this library: "Pure Lua Date & Time module for Lua 5.x featuring date and Time string parsing, time addition & subtraction, time span calculation, support for ISO 8601 Dates, local time support, strftime-like formatting.")

Platform agnostic.

Lua Methods

Lua methods for date/time handling.

Date Formatting Functions

The following code provides date formatting functions which are not available in the string.format function.

Ideal for formatting dates in reports, or converting dates between different formats when importing data.
http://lua-users.org/wiki/DateFormattingFunctions

Day Of Week And Days In Month Example

"The following code provides date functions that include calculating the number of days in a given month and the day of week for a given calendar day."

http://lua-users.org/wiki/DayOfWeekAndDaysInMonthExample

Display Calendar In Html

Displays a Calendar in HTML

http://lua-users.org/wiki/DisplayCalendarInHtml.

Finding the Right Date Format

A lua script to look up encoding for fetching dates using os.execute. http://snippets.luacode.org/snippets/Finding_the_right_date_format_103.

Lua Date Formatting Functions

http://lua-users.org/wiki/DateFormattingFunctions ("The following code provides date formatting functions which are not available in the string.format function. Ideal for formatting dates in reports, or converting dates between different formats when importing data").

Rosetta Code Lua Snippets

Category: Lua, at RosettaCode.org. Includes links to snippets for date handling:

 Date format
 Date manipulation
 Day of the week
 Leap year


http://rosettacode.org/wiki/Category:Lua

There may be others on that site that weren't categorized properly.

Time Zone Function

Time Zone, Lua function that portably returns a timezone string in the form +hhmm or -hhmm, http://lua-users.org/wiki/TimeZone.

Unit Conversion

This code provides a convert_to function that converts between any two units on a scale defined in a table in pairs of {name, equivalent number of previous unit}. The example given is time, but it can be adapted for Imperial units, military divisions, pre-decimalisation British pounds, or any other incremental system of measurement.
http://lua-users.org/wiki/UnitConversion