Giter Club home page Giter Club logo

datetime's People

Contributors

bubblebenj avatar jonnydee avatar klabz avatar laurence-myers avatar postite avatar realyuniquename avatar sh-dave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datetime's Issues

Allow ISO 8601 timezone offset in `DateTime.fromString()`

The DateTime.fromString() method only allows ISO 8601 dates that have the following format:
YYYY-MM-DDThh:mm:ss[.SSS]Z

But it is very common to have dates that use a timezone offset, like 2020-04-24T16:20:07+02:00.

So it would be cool if the DateTime.fromString() method supported dates using a timezone offset.
Currently, it's very hard to deal with ISO 8601 dates in Haxe!

Feature Request: date.snap( Day(Up) )

I would love to see a "snap()" function similar to your "add()" function.

You could define direction as an abstract enum:

@:enum abstract SnapDirection {
    var Up = 1;
    var Down = -1;
    var Round = 0;
}

I have a function similar to this in my fork of Franco's THX library and it's date class:

https://github.com/ufront/ufront-mvc/blob/master/src/Dates.hx#L145

I want to abandon that class anyway though for a clean abstract approach like this, so I'll request the missing features if you're interested :)

Count is different in Flash and Windows targets

Doing a simple clock for football matches, counts up to 45 minutes from zero, or to 90 minutes from 45.
Noticed this: if I compile to flash all goes well, but if I compile to windows every time it goes up to sometime:59 it displays sometime:00 before doing sometime+1:00. It is like it is clearing the seconds before updating the minutes, but only in c++.

Attaching .zip with project to illustrate this better. It runs perfect on flash but the same code displays the extra time position when compiled to windows. You can use the keypad's "*" to increase seconds up to the minute change, around sometime:59, and watch what it does. Just press button "45" to start it.

score_crono.zip

More utc/local functions

Something like that:

public function toLocal() : DateTime {
        return getTime() + getLocalOffset();
}//function toLocal()

static public inline function fromUtcTime (time:Float) : DateTime {
    return new DateTime(time + getLocalOffset());
}//function fromTime()

static public inline function fromUtcString (str:String) : DateTime {
    return DateTimeUtils.fromString(str).toLocal();
}//function fromString()

static public inline function fromUtcDate (date:Date) : DateTime {
    return Math.ffloor(date.getTime() / 1000 + getLocalOffset());
}//function fromDate()

// or make it public (why it is private?)

static public function getLocalOffset () : Int {
        var now   = Date.now();
        var local = make(now.getFullYear(), now.getMonth() + 1, now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());

        return Std.int(local.getTime() - Std.int(now.getTime() / 1000));
}//function getLocalOffset()

`DateTime.fromString()` allows invalid ISO 8601 dates

An ISO date like 2000-13-48T00:00:00Z or 2000-01-01T29:73:82Z is invalid: the DateTime.fromString() method should throw an exception in this case.
Instead, it returns a date where the timestamp is adjusted according to the "overflow": 2001-01-17 00:00:00 for 2000-13-48T00:00:00Z, 2000-01-02 06:14:22 for 2000-01-01T29:73:82Z.

API docs link may be stale

When I click the API Docs link in the README.md (pointing to the url doc.stablex.ru/datetime/index.html), it's taking forever to load in Firefox, and eventually giving this timeout:

image

Do the docs need to be migrated somewhere else?

nov2020.add(Month(1)) adds 13 months

var nov = DateTime.fromString("2020-11-01 00:00:00");
trace(nov); // 2020-11-01 00:00:00
var dec = nov.add(Month(1));
trace(dec); // 2021-12-01 00:00:00

Should happen for any addMonth ending in december.

Wrong result of interval.getTotalMonths

Consider interval of 2021-06-26, 2022-06-25. interval.getTotalMonths returns -1 instead of 11.

Here's my code fix it outside of datetime package.

@:access(datetime)
class IntervalFix {
	public static function getTotalMonthsFix(interval:DateTimeIntervalCore) {
		final begin = interval.begin;
		final end = interval.end;
		var months = (end.getYear() - begin.getYear()) * 12 + (end.getMonth() - begin.getMonth());
		var d1 = begin.getDay();
		var d2 = end.getDay();
		if (d2 < d1) {
			months --;
		} else if (d1 == d2) {
			var h1 = begin.getHour();
			var h2 = end.getHour();
			if (h2 < h1) {
				months --;
			} else if (h2 == h1) {
				var m1 = begin.getMinute();
				var m2 = end.getMinute();
				if (m2 < m1) {
					months --;
				} else if (m2 == m1 && end.getSecond() < begin.getSecond()) {
					months --;
				}
			}
		}
		return months;
	}
}

Can not use datetime on Android

I has installed datetime on haxe (haxelib install datetime) to get timezone offset. It run ok on Neko. But when I run on Android (lime test android), it runtime error. What's wrong?
Please help me.
Thanks.

import datetime.DateTime;
import datetime.Timezone;
class DateHelper
{
public function getTimeZone():Void{
trace(Timezone.local().getOffset(DateTime.local()));
}
}

bug when year change

var d = DateTime.now();
Sys.println(d.getDate());
		
var a = d.snap(Month(Down)).add(Month(-6));
Sys.println(a.getDate());

outputs

2017-06-06 14:31:36
2017-12-01 01:00:00

Why the second date is not 2016-12-01 01:00:00
Why the hour is not 00:00:00 ? ( because of day light saving ?? )

( I'm using haxe 3.2.1 with neko )

Another strange case

var d = DateTime.now();
Sys.println(d.getDate());
		
var a = d.snap(Month(Down)).add(Month(-2));
Sys.println(a.getDate());

outputs

2017-06-06 14:36:47
2017-04-01 02:00:00

Why the hour is not 00:00:00 ?

Feature Request: Operator Overloading

Addition / subtraction:

DateTime.now() += Week(1);
DateTime.now() -= Month(1);

Comparison

dateTime1 != dateTime2
dateTime1 == dateTime2
dateTime1 > dateTime2
dateTime1 < dateTime2

Again, just throwing out ideas because this is something I wanted to do but haven't gotten around to, so excited to see where your library might head :)

DayCounter to simplify looping dates.

I found it useful to create a simple DayCounter for my Covid19 project. I convert dates from a string in the csv data using your library and use my DayCounter to easily control days I render.

Perhaps something like day counter would be useful directly in datetime if not then left here incase useful for others, I expect you could create a date and then increment it by one day but this seemed clearer to work with a cut down format, perhaps you have similar feature already that I missed.

import datetime.DateTime;
@:structInit
class InternalDayCounter {
    public var day: Int;
    public var month: Int;
    public var year: Int;
    function new( day:  Int, month: Int, year:  Int ){
        this.day  = day;
        this.month  = month;
        this.year = year;
    }
}
@:forward
abstract DayCounter( InternalDayCounter ) from InternalDayCounter to InternalDayCounter {
    public inline
    function new( v: InternalDayCounter ){ this = v; }
    public inline
    function hasNext(){
        return true;
    }
    public inline
    function next(){
        var isLeap = DateTime.isLeap( this.year );
        var dayTot = DateTime.daysInMonth( this.month, isLeap );
        this.day++;
        if( this.day > dayTot ) {
            this.day = 1;
            this.month++;
            if( this.month > 12 ) {
                this.month = 1;
                this.year++;
            }
        }
    }
    public inline
    function matchDate( date: DateTime ){
        return date.getDay() == this.day && date.getMonth() == this.month && date.getYear() == this.year;
    }
}

typical use

var dayCounter = new DayCounter({day:5,month:3,year:2020});
function renderDay(){ // every so many frames
   var renderData = new Array<MyData>();  // MyData would contain date and some data values.
   var j = 0;
   for( d in myData ) {
      if( dayCounter.matchDate( d.date ) ) renderData[ j++ ] = d;
  }
  plot( renderData ); // plot data to screen
  dayCounter.next();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.